[Solved] Find and replace character in web page [closed]


If you can’t use developer tools and really need the regex to search through the source file (and it’s an actual text character x), then this (probably inelegant) regex should do it:

(\Wx\W)|(^x\W)|(\Wx$)

The \W means “not a ‘word’ character”. This may or may not quite work for you depending on what you have in the source file (particularly if you have UTF-8/international characters, I’m not sure how Sublime Text 2 will treat all of that with relation to \W).

^ means “beginning of line”. $ means “end of line”. An x at the start or end of a line, with no other ‘word’ characters around it would count!

The ( ) are merely logical groupings (can be used as matched references in other cases like replacing text), and the | means “or” (so the regex is simultaneously looking for three different patterns, here). The x is just the literal character.

Tests from Sublime Text 2 follow.

Matches:

x as
x asdf
asdf x
asdf x asdf
as x
>x
a x<

Doesn’t match:

xas
asdxafd
asdfx

You really should make an attempt, too. It often leads to a better understanding of the problem (in this case, understanding regular expressions).

1

solved Find and replace character in web page [closed]