Regex only on first occurrence

0

I'm using the sublime and would like to do a bulk replace. My texts are in this pattern:

ABC ("Teste regex

I would like to remove the space after ABC and should look like this:

ABC("Teste regex

What would be the regex?

    
asked by anonymous 04.01.2018 / 18:43

2 answers

1

It's pretty simple.

In search, use the following regex: (ABC)\s .

Where it is in parentheses is the content that will remain and the rest outside the group is what is going to be deleted.

In the content to replace, use $1 .

So basically we're picking up everything that was found in the "ABC" regex and replacing it with the contents of the first group of the regex that is "ABC".

  

$ 1 indicates that you are getting everything found in the first group of the regex, the parentheses define a group.

See working at RegExr

Remembering that \s takes spaces, line breaks, tabs, etc. If you want to take only the space, you can put a space at the end.

    
04.01.2018 / 19:07
0

If your intention is to remove one or more spaces before a parenthesis you can do this:

  • O\sservestocapturespaces,tabs,linebreaks,etc.
  • The*soonaftermeansthatthisspacecanoccureitherorseveraltimes.
  • Andfinallythe(representstheopeningoftheparentheses,butsincethisisaspecialcharacterforregexwehavetoaddthebarbeforetoescape.

    Find:\s*(

    Replace:(

Asismispossibletocatchseveraltypesofsituation:

    
04.01.2018 / 19:56