• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular expression help  RSS feed

 
Taco Fleur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two regular expressions, one needs to get the following part from a string.

ZHDASCTXID0400\nZTX777Y20050711777571\nZTRENDTXID3\n

The other needs to get the following part of the string

ZXCthis is the certificate\nZXIthis is the namett777key\nZXSeOOofcbWkqDikY9/Cq0H2lrRMZ+GY0urZE8bDhQ8vIqufhGx+XEKWLCAscYIT4CS\nZXSlWMH+ixj89G6beKfoV7r9HABw8i55icaQCWcQ36CYoejWpUKhp2
ROjZdK0h3mywo\nZXSt6v6YrHqWKYOv5QLiUtpN1sxqBeZxGCTcmPjrF2rcW0=\n

[Line break inserted in above line for readability - Jim]

The complete string is the two combined.
The regexs' are:



I get a "No match available" error.
I use regex quite often but in another language, so not sure if its my expression or not.

[ July 12, 2005: Message edited by: Jim Yingst ]
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your first problem is that you never actually apply the regex. You have to call one of the methods matches(), find() or lookingAt() to do that. But your regexes still won't work because the '.' metacharacter doesn't normally match linefeeds. That's easy to change, but then you have to make sure the first ".*" in SIGNATURE_REGEX doesn't gobble up the rest of the string. You can use the non-greedy version, ".*?" for that, as shown below (I also made the first ".*" non-greedy, but that's just for efficiency).
 
Taco Fleur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a bunch I am working on this now.

Any idea how to escape the ][ chars within a character class?
 
Taco Fleur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked like a charm.. thanks..

Not sure how this works, do I open a new thread if I have another related question, or just post it here as well?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Taco]: Any idea how to escape the ][ chars within a character class?

As "\\[" and "\\]", the same as for other escape sequences in Java regexes. The first \ is for the Java compiler; the second is for the regex compiler (in the Pattern class).

Not sure how this works, do I open a new thread if I have another related question, or just post it here as well?

If it's related to the topic so far, then you can post it here. Of course, this is a judgement call; it depends how closely related it really is. Try this: if you posted it in a new thread, would you need to repeat some of the info you've already provided in this thread? If so, you should probably post it here instead.

Also: is "Taco Fleur" a real name in some culture? It looks suspiciously made-up to me, which would suggest that you should reread our display name policy and edit your display name to something a bit less fictitious-looking. Thanks.
 
Taco Fleur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could be asking the same about "Jim Yingst" Looks to me like Jim is a made up name since your last name looks asian ;-)

And yes it is my real name - Good thing is, there is only ONE Taco Fleur in the whole wide world! ;-)

Thanks.
 
Taco Fleur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PS. any idea why I am not getting an alert via my email when a new reply is posted? I am assuming you are one of the admins.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Taco]: And yes it is my real name

Okey-doke. Just checking.

PS. any idea why I am not getting an alert via my email when a new reply is posted?

It looks like you didn't check the "Email Notification" checkbox when you created this topic. Unfortunately this option is only available when you create the topic, and only if you're the one who created it. I've edited this thread now so that you should receive notifications.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!