2

I want to match the following expression in notepad ++, how can I do that ? <table align="center" cellpadding="4" cellspacing="3" border="1" bgcolor="#B1A0C7">

I want to match from the beginning of <table and then all in between characters and stop at the first >

i did the following but it doesn't work for me (<table).*>$ it keep getting the last > in the line ... I want the first >

2 Answers 2

5

Try this:

<table[^>]*?>

explain:

*? Matches the previous element zero or more times, but as few times as possible.

[^character_group] Negation: Matches any single character that is not in character_group.

1
  • What if you have a newline in your <table> tag, as is sometimes used to make those more readable, when a lot of properties are added?
    – Cerbrus
    Commented Jan 9, 2013 at 9:35
2

Try this:

<table[^>]*>

Use [^>] to match any character but >, making it select only that first tag. This will include newline characters, so this regex will work for:

<table align="center"
       cellpadding="4"
       cellspacing="3"
       border="1"
       bgcolor="#B1A0C7">
3
  • <table[^>]*>$ will only match first line matched .. if there is more in the page won't match .. i think
    – osos
    Commented Jan 9, 2013 at 9:48
  • @osos: I copied the $ from your attempt, assuming that's what you wanted. Without it (As edited), it will match any table element. Too bad someone else thought it was a good idea to basically copy my answer.
    – Cerbrus
    Commented Jan 9, 2013 at 9:49
  • @Cerbrus: +1 for using [^>]
    – Ria
    Commented Jan 9, 2013 at 10:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.