0

How to match missing period (.) before end tag using regex?

To make myself clear, here's a sample:

Samples need match:

1. text</… ></tag> ---> Where </...> is any tag and can be multiple end tags

2. text</tag>  

Correct samples that don't need to match:

1. text.</...></tag>
2. text.</tag>

and I want to ignore something like this:

,</tag>   --> Where , can be any punctuation except period (.)

or

,</...></tag>

I hope someone can help me thanks alot!

jomsk1e
  • 3,585
  • 7
  • 34
  • 59
  • I'm confused... you want to match places where you have a period before an end tag? Or you want to match places where you don't have a period before an end tag? – drewmm Mar 20 '13 at 08:49
  • It would be more clear if you provided pure text examples, instead of mixing regex and text. – Adam Adamaszek Mar 20 '13 at 08:50

3 Answers3

1

Just simply use [^\.]. This will match anything but . In your case you need to use [^\.>]</

Mostafa Shahverdy
  • 2,687
  • 2
  • 30
  • 51
  • how do I check if this is before ? and before sometimes this may occur, , and can occur multiple times before – jomsk1e Mar 20 '13 at 09:05
  • Let it occur! if there is any `text` in any part of your string, then this will check it – Mostafa Shahverdy Mar 20 '13 at 09:06
  • but I only need to match those text without period (.) before the . So you mean to say I will match text even if it is not before – jomsk1e Mar 20 '13 at 09:09
  • What I mean to say is I don't need to match text without period if it is not before the . For example "this is a text". Your answer will match 'text', which I dont want to happen because it is not inside – jomsk1e Mar 20 '13 at 09:15
0

[,;:] will match any punctuation except period. Extend at your leisure (as I'm not sure whether you want chars like apostrophe, quotation, slash etc.)

You can also negate that by using [^,;:], where ^ stands for NOT in the character set.

See this for reference.

Adam Adamaszek
  • 3,914
  • 1
  • 19
  • 24
0

This is what I've done with my problem:

([^.:;(or)(and)\!\)()>])(\</.*?\>)\</tag\>

This will match text without period (.) before end :

text</otherEndTag>...</tag>

But the punctuation list will be ignored:

: ; ! ) ( > , or , and
jomsk1e
  • 3,585
  • 7
  • 34
  • 59