Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

match first space on a line using sublime text and regular expressions

So regular expressions have always been tough for me. Im getting frustrated trying to find a regular expression that will select the first white space on a line. So then i can use sublime text to replace that with a /

If you could give a quick explanation that would help to

like image 244
Mr. MonoChrome Avatar asked Oct 18 '13 22:10

Mr. MonoChrome


1 Answers

In the spirit of @edi's answer, but with some explanation of what's happening. Match the beginning of the line with ^, then look for a sequence of characters that are not whitespace with [^\s]* or \S* (the former may work in more editors, libraries, etc than the latter), then find the first whitespace character with \s. Putting these together, you have

^[^\s]*\s 

You may want to group the non-whitespace and whitespace parts, so you can do the replacement you're talking about:

^([^\s]*)(\s) 

Then the replacement pattern is just \1/

like image 97
Matt Tenenbaum Avatar answered Sep 21 '22 03:09

Matt Tenenbaum