Replace: forced to use regexp?

Hello,

Please consider the following string:


*hello = some sentence;

That same pattern occurs across a document. I’d like to get rid of such occurences.

The string to remove always:
-starts with a ‘*’
-is followed by no space/tab, one space/tab or multiple spaces/tabs
-then has a ‘=’
-which is followed by whatever (from nothing, to white space, to tabs, to complex strings)
-and ends with a ‘;’

How would you do it?

Regards,

-jj. :slight_smile:

Try this regular expression

\\s=[^;]*;

\* - look for a asterisk (escaped because want an actual asterisk)
\s* - zero of more whitespace
= - an equals sign
[^;]* - any characters except a semi colon you could also do .*? (anything but don’t be greedy)
; - a semi colon itself

Yeah! Thanks :slight_smile:

as far as the ‘forced to use regexp’… the answer is: If you have any optional part of the string, then you must either use a regex, or a lot (read: potentially infinite) of replaces (to cover all eventualities).
If, in defining what you’re looking for, you use one or more of the phrases ‘<a number> or more’ (even if that number is 0), ‘either’, ‘one of’ or ‘containing’, you’re most likely talking about a regular expression.