Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
How can I capture a specific char inside specific strings with regex?

I want to replace all the dots -that are inside specific strings- by underscores. In my case, I'm using i18n (for translations) inside my application, and the keys are called using '$t(key)'. Key can be like that :

key = 'translationKey'
key = 'translationKey.subkey.subSubkey'
key = 'translationKey.subkey.one'
key = 'translationKey.subkey.zero'
key = 'translationKey.subkey.others'

In the $t context: I want to transform the dots (.) that are not followed by one or zero or others into underscore (_). If I have those inputs :

foo.toto.anything
$t('translationKey')
$t('translationKey.subkey.subSubkey')
$t('translationKey.subkey.one')
$t('translationKey.subkey.zero')
$t('translationKey.subkey.others')

Then the output will be :

foo.toto.anything
$t('translationKey')
$t('translationKey_subkey_subSubkey')
$t('translationKey_subkey.one')
$t('translationKey_subkey.zero')
$t('translationKey_subkey.others')

I'd like to use Vscode regex search to capture those dots and to replace them (if possible).

I only managed to get all the strings where the target dots are, but I can't reach only the dots. Here's the the regex I have atm: (\$|\.)t?t(c|p)?('(\w+\.?)*')

Thank you

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use

(?<=\$t\('[^']*)\.(?!(?:one|zero|others)')(?=[^']*'\))

See the regex demo. Details:

  • (?<=\$t\('[^']*) - a positive lookbehind that requires $t(' and then any zero or more chars other than ' immediately to the left of the current location
  • \. - a dot
  • (?!(?:one|zero|others)') - a negative lookahead that fails the match if there are one', zero', or others' immediately to the right of the current location
  • (?=[^']*'\)) - a positive lookahead that requires zero or more chars other than ' and then ').
about 4 years ago · Juan Pablo Isaza Report

0

The following regular expression should work: it matches all the dots not followed by "one", "others", and "zero"

(?<=\$t\('[^']+)\.(?!one|others|zero)

You can test it online here

https://regex101.com/r/84Jil1/1

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!