1

parameter

In Sublime Text 3 I am using the following RegEx code as my search combo to find any alphabet character preceding 0, followed by a space, followed by another character which is as follows:

RegEx Code

[a-z]0 [a-z]

Search Target Examples

Eg.1  a0 p
Eg.2  p0 sa
Eg.3  ap0 l

Question: What RegEx code should I write so that it replaces all such occurrences containing the 0s with a dot (.) i.e., it should become like this:
Replace Objective of Target Examples

Eg.1  a0 p    → a. p
Eg.2  p0 s    → p. sa
Eg.3  ap0 l   → ap. l

1 Answers1

1

Use capturing groups and backreferences:

Regex: ([a-z])0( [a-z])
Replacement: $1.$2

See the regex demo

Details:

  • ([a-z]) - matches and captures into Group 1 any ASCII lowercase letter
  • 0 - a literal 0 is matched
  • ( [a-z]) - Group 2: a space and a lowercase ASCII letter

The replacement contains the backreference to the value stored in Group 1 ($1), then we replace 0 with a dot, and use the backreference to Group 2 contents ($2).

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Glad it worked for you. Please also consider upvoting if my answer proved helpful to you (see [How to upvote on Stack Overflow?](http://meta.stackexchange.com/questions/173399/how-to-upvote-on-stack-overflow)). – Wiktor Stribiżew Nov 18 '16 at 06:28
  • I actually did upvoted your post in addition to marking it as an answer. However for some reasons, it did not get upvoted at the first attempted. I have done it again and should work now. – VinayaŚiṣya Nov 18 '16 at 15:28
  • Hi Wiktor. I got the same issue but this time it's the **॥** char wrapping numbers and they are in italics (in a word document) and in each line, it goes something like that ** ॥ 4 ॥**, **॥ 5 ॥**, **॥ 6 ॥** ... **॥ 36 ॥**, **॥ 37 ॥** etc. What RegEx code to type to select them and change it from italic to regular. – VinayaŚiṣya May 31 '17 at 04:53
  • @VinayaŚiṣya: Sorry, no idea what you mean. If it is a new question, please post. – Wiktor Stribiżew May 31 '17 at 07:01