Forum Moderators: open

Message Too Old, No Replies

How to regex in Notepad2

Help needed

         

Hester

10:06 am on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to find and replace FONT tags in a document using Notepad2's regex feature. But I can't seem to get the results to match what I want. I wish to find everything inside an opening FONT tag and replace it with nothing.

Eg: match any of the following examples, but nothing more on the line:


<FONT color=#0000ff size=2>
<FONT face=Verdana size=2>
<FONT size=5>

I've studied the help file that comes with Notepad2 as this tells you what regex commands to use.

Here's what I've been trying, but nothing works properly - it catches the start of the tag, but also highlights other tags beyond it.


<FONT\(.*>\)

<FONT\(.*\>\)

<FONT\(.*\)\>

<FONT\(.*\)>

Can you tell I'm fairly new to regex? What do I need to use to make it work?

saul11

4:03 pm on Sep 12, 2004 (gmt 0)

10+ Year Member



<FONT.*?> should work.

This matches '<FONT' and everything before the first '>'. It includes '>' in the match too.

<FONT
. (any character)
* (zero or more times)? (non-greedy)
>

Hester

8:56 am on Sep 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately Notepad2 doesn't seem to allow "?". (It's not mentioned in the help file list.) I tried your example and it couldn't find anything.

lexipixel

10:06 am on Sep 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Unfortunately Notepad2 doesn't seem to allow "?". (It's not mentioned in the help file list.) I tried your example and it couldn't find anything.

-Hester

Have you tried escaping the '?' with &#63; or %3F

Hester

10:28 am on Sep 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It doesn't work. The help file declares a set list of commands, so I guess only those are implemented.

Regular Expression Syntax

. Matches any character

\( This marks the start of a region for tagging a match.

\) This marks the end of a tagged region.

\n Where n is 1 through 9 refers to the first through ninth
tagged region when replacing. For example, if the search
string was Fred\([1-9]\)XXX and the replace string was
Sam\1YYY, when applied to Fred2XXX this would generate
Sam2YYY.

\< This matches the start of a word.

\> This matches the end of a word.

\x This allows you to use a character x that would otherwise
have a special meaning. For example, \[ would be interpreted
as [ and not as the start of a character set.

[...] This indicates a set of characters, for example, [abc] means
any of the characters a, b or c. You can also use ranges, for
example [a-z] for any lower case character.

[^...] The complement of the characters in the set. For example,
[^A-Za-z] means any character except an alphabetic character.

^ This matches the start of a line (unless used inside a set,
see above).

$ This matches the end of a line.

* This matches 0 or more times. For example, Sa*m matches Sm,
Sam, Saam, Saaam and so on.

+ This matches 1 or more times. For example, Sa+m matches Sam,
Saam, Saaam and so on.

-----> Examples (don't use quotes)
- Quote lines: find "^" replace with "> "
- Unquote lines: find "^> " replace with ""
- Remove line numbers: find "^[0-9]+" replace with ""
- Convert tabs to double spaces: find "\t" replace with " "

lexipixel

9:43 pm on Sep 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




\x This allows you to use a character x that would otherwise have a special meaning. For example, \[ would be interpreted as [ and not as the start of a character set.

Have you tried \?

I don't Notepad2, so I am just suggesting things I'd try.

Hester

8:55 am on Sep 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It doesn't seem to work either.

lexipixel

6:37 am on Sep 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The docs do say, "Basic regular expression search and replace", you might have to make do with what is documented.

You could contact 'Flo' and ask about it.

There are other NotePad replacements...