Sublime Forum

Regex don't work - delete everything before "WORD"

#1

hello. I have this Regex.

This will delete everything before “WORD”

Search:
[\s\S]*.*(WORD).*[\s\S]

Replace with:
leave empty

I test this with notepad++ and or GrepWin and works great. Works with sublime.

But, if I put in the same expression with some other word, like “bebe”, it doesn’t work on Sublime, but works with the other 2 editors.

[\s\S]*.*(bebe).*[\s\S] (not working)

0 Likes

#2

I’m not sure what you expect here.
It sounds like you want to delete everything before the WORD, for example in:

This is a sentence with a WORD in it

you want to delete:

This is a sentence with a

correct?

If that’s the case then your regex will not match that part of the sentence.
[\s\S].(WORD).*[\s\S] will match a WORD in it and replacing that match with nothing will leave you with:

This is a sentence with

Could you provide an example of what you expect to happen? Because as it stands your regex doesn’t match up with your explanation as far as I can see.

0 Likes

#3

sorry, seems I forget to Blockquote, and was a wrong formula.

I wrote again:

[\s\S]*.*(WORD).*[\s\S]

Replace with:
leave empty

Example:

Father 123

This is a sentence with a WORD in it

mother

The regex will delete all lines included that one with the WORD in it. And will leave “mother”

The problem in Sublime is that if I replace WORD with another one, like “bebe”, the same regex will not work. But works very well with notepad++ or GrepWin.

0 Likes

#4

This seems to work perfectly fine for me.

If I use the text:

Father 123

This is a sentence with a WORD in it

1234 bebe 123

testing 123

mother

with the regex [\s\S]*.*(bebe).*[\s\S], it will select everything from the beginning of the file up to the end of the line that contains the word bebe in the same way it did with WORD.

0 Likes

#5

I don’t know, maybe I didn’t check something on sublime options…

0 Likes

#6

This is what I just tried, and it worked fine:

^[^\n]*\<WORD\>[^\n]*$

^[^\n]*\<bebe\>[^\n]*$
0 Likes

#7

it is not the same.

Your regex delete only the row that has some words.

The regex I discuss [\s\S]*.*(WORD).*[\s\S] deletes everything included the lines before WORD.

0 Likes

#8

This is another very good suggestion:

((?s)((^.*)WORD))(.*$)

0 Likes