Sublime Forum

Regex to insert, not replace

#1

Hi there, I am using sublime text since it supports regex in the search field. I am essentially running a match for:

\s6[0-9][0-9][0-9]\s

And then what I want to do is insert a new line (\n) in front of that (not replace it). My Sample data looks like:

6309 ,9044XXXXXXXXXX ,"Jul 8, 2013 5:49:36 AM",42 ,Others,Some Name 6207 ,901XXXXXXXXXX ,"Jul 8, 2013 6:13:50 AM",4 ,Others,Another Name 6211 ,9044XXXXXXXXXX ,"Jul 8, 2013 6:22:00 AM",24 ,Others,Onemore Name

And I want to get it to:

6309 ,9044XXXXXXXXXX ,"Jul 8, 2013 5:49:36 AM",42 ,Others,Some Name
6207 ,901XXXXXXXXXX ,"Jul 8, 2013 6:13:50 AM",4 ,Others,Another Name
6211 ,9044XXXXXXXXXX ,"Jul 8, 2013 6:22:00 AM",24 ,Others,Onemore Name

The issue I have , is that since each line may have a different 6XXX number, I cannot just replace 6XXX with \n6XXX - unless there is some way to pass the actual match over and reinsert it…

Any ideas?
Thanks!

0 Likes

#2

Search:

(6[0-9]{3})

replace:

\n\1

:smile:

0 Likes

#3

[quote=“qgates”]Search:

(6[0-9]{3})

replace:

\n\1

:smile:[/quote]

You sir, are a gentleman and a scholar. That was driving me nuts!

0 Likes

#4

[quote=“qgates”]Search:

(6[0-9]{3})

replace:

\n\1

:smile:[/quote]

OOPS… I forgot to mention, that in the sample data, the “XXXXXX”'s I had listed above are also numbers (I was just removing the real phone numbers). So for example, the sample data may actually look like:

6309 ,90446150000000 ,"Jul 8, 2013 5:49:36 AM",42 ,Others,Some Name 6207 ,90446250000000 ,"Jul 8, 2013 6:13:50 AM",4 ,Others,SomeOther Name 6211 ,90446350000000 ,"Jul 8, 2013 6:22:00 AM",24 ,Others,Another Name 6353 ,90446450000000 ,"Jul 8, 2013 6:22:05 AM",50 ,Others,Name Name 6236 ,90446550000000 ,"Jul 8, 2013 6:37:16 AM",21 ,Others,Last Name

So based on what you posted, the pattern may also match on the full phone numbers.

IE.

6309 ,90446150000000 ,“Jul 8, 2013 5:49:36 AM”,42 ,Others,Some Name

Then I end up with another split in the ,middle as well.

So, If i take your example and try…

\s(6[0-9]{3})\s

My assumption is that it will work.

Just posting for a complete answer. I’ll test and reply back once I get to my sample data.

0 Likes

#5

You can also use \d to match a digit and \D to match a non-digit.

0 Likes