reg ex

How Can I write a regular expression which accepts the following parameter.
I'm creating a pattern, which should split the string if exist....I'm doing splitting array and returning an linked list on that........

My regular expression should consist of following values............. (<br></br> (or) <p> (or) </p> (or) <!-- end -->)
Who is Participating?
ZvonkoConnect With a Mentor Systems architectCommented:
Look at your initial question and tell me how many questions did I answer so far.

And tell me wether you look for two <Br> <Br> or can it be <Br> <br> or <BR> <BR>? Or do you know what, give me this points and open new question for two br's ;-)

ZvonkoSystems architectCommented:

Like this:


var yourString="some text<br>more text:<p>example</p>and <!-- end --> the end!";

alert(yourString.split(/<[\/\!]?(br|p|-- end --)>/i).join("\n"));


Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ZvonkoSystems architectCommented:
The expression alone is this:

 /<[\/\!]?(br|p|-- end --)>/i

But I think you see that :)

Suda_RamanaReddyAuthor Commented:
Hi Zvonko....

Based on your guidance I'm writing it now as "String regex = "<?(br|p|!-- page break --)>".............  I still need little modification on this... like... It should be identifying occurances of .................."Two continuous <Br>'s and a single occurance of <p> and <!-- page break --> ".   Also I needs to make it case Senstive.  I'm really strucking at how can I look for two continuos <Br>'s.... while looking for only a single occurance of <p> and <!-- page break -->. Is there any (or) two do this. Sth like <?(p|!-- page break -->)> or <[Br]*>..?
ZvonkoSystems architectCommented:
How should the split() work for two <br>s? Can you post an example.
Give a big imput and desired output that covers most of your permutations.

Suda_RamanaReddyAuthor Commented:
My input is Some thing like this...

1st Chunk <p> 2nd Chunk <Br> <Br> 3rd Chunk <br> 4th Chunk <p> 5th Chunk <p> 6th Chunk <Br> <Br> 7 th Chunk <br> 8 th Chunk <!-- page break -->

I am accepting this regular expression as a string and Splitting it...! When ever I see <Br> <Br> in the i/p String.. I should be able to identify it...!

Thanks once again for your fast response.
Suda_RamanaReddyAuthor Commented:
Sorry and my output  should be

"1st Chunk  2nd Chunk  3rd Chunk  4th Chunk  5th Chunk  6th Chunk  7 th Chunk  8 th Chunk"
ZvonkoSystems architectCommented:
Check this:

String regex = "<[\/\!]?(r|p|-- (end|page break) --)>(\s+<br>)?";

And I do not see why to distinguish betwean <br> and <Br>

ZvonkoSystems architectCommented:
Sorry, the first b in br disapiered by copy.

Check this:

String regex = "<[\/\!]?(br|p|-- (end|page break) --)>(\s+<br>)?";

Suda_RamanaReddyAuthor Commented:
Hi Zvonko..

I'm doing this for pagination application, where I 'm trying to split an article and trying to spread it across the pages.  Basically it might be in HTML and  as you know <br> elements may present there. So.. they opted for continuos occurances of <Br> ( some thing like <Br> <Br>) and hence I asked for CASE Sensitive....

Sorry to trouble you.. but... can you explain little bit about above regular expression?

Coming to the application...I did it with a simple regular expression and an able to split it, when ever I found a chunk. Now they added these new stuff to that...! Hence trying to wrap everything in RE..
ZvonkoSystems architectCommented:
Of course I can ;-)

Split separation marker can consist of this characters:
  "<"   : first char of split marker has always to be that char
  [\/\!]?  : second char can be (the can is because of ? mark) a "/" char or a "!" char as declared inside the set []
  (br|p|-- (end|page break) --)  : now you look for a sequence to follow. The sequences are defined by the or meta character pipe: |  and all options are enclosed in a group delimeted by round braces.
  ">"   :   after one option from the group the char ">" has to follow
  (\s+<br>)?     : this whole group is optional because of the ? mark
  \s+  :  one or more space characters
   "<br>"   : the sequence as it is

End of split separator mark

Suda_RamanaReddyAuthor Commented:
Thanks Zvonko..
a simple correction to this regular expression is needed. I want to identify the pattern String with two or more <Br>'s..... but not for a single <Br>. Below one is working fine for two or more <Br>'s.....  BUT IT ALSO "recognizing a single <Br> as a pattern string..!" which is not required.
String regex = "<(Br|p|!-- page break --)>+( <Br>)*";

So in simple...
It should identify two or more <Br> 's.... a single <p> a single <!-- Page Break -->.

All I need is.. I want to avoid it from detecting for a single <Br> as a pattern String. I can keep a ? instead of *.. but then it is taking only two <Br>'s.. but not taking more.. I can not keep a + because then it will recognize pattern String of type <p> <Br> which Is not required...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.