[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

reg ex

Hi,
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 -->)
Thanks
0
Suda_RamanaReddy
Asked:
Suda_RamanaReddy
  • 7
  • 5
1 Solution
 
ozoCommented:
<[^<>]*>
0
 
ZvonkoSystems architectCommented:

Like this:

<script>

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

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

</script>




0
 
ZvonkoSystems architectCommented:
The expression alone is this:

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

But I think you see that :)

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Suda_RamanaReddyAuthor Commented:
Hi Zvonko....

Thanks...
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]*>..?
0
 
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.

0
 
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.
0
 
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"
0
 
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>

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

Check this:

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


0
 
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..
0
 
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


0
 
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...





0
 
ZvonkoSystems 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 ;-)

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now