1

I'm not a pro in Regex, therefore I'm having a difficulty translating this regex pattern to Java.

I believe it would be an easy task to a guy which is familiar enough with Regex. I have seen similar topics, however - each topic is relevant for a specific regex pattern...

The Pattern is:

@"\<meta name=""title"" content=""(?<title>.*)""\>"

Thanks in advance!

3
  • The only thing interesting I see in there is the double-quotes. Remove the @ at the front, un-double the quotes and escape them instead (with a backslash). Commented Mar 25, 2012 at 17:57
  • I did so. I didn't just copy-paste it to Java... I removed the '@' and changed the special characters to * (e.g. \" instead of "" and \\ instead of ), and yet I got an exception that this is not a valid Regex Pattern Commented Mar 25, 2012 at 18:00
  • 2
    It's probably the named capture. I cant find any straight answer on if Java supports them. Try taking it out. Replace (?<title>.*) with just (.*) (Edit: Actually, apparently Java7 does but not prior stackoverflow.com/a/415635/65387) Commented Mar 25, 2012 at 18:06

1 Answer 1

1

If you want slashes in front of the openning and closing angle-brackets, use this (escaped for Java):

"\\\\<meta name=\"title\" content=\"(.*)\"\\\\>"

Without them, use this:

"<meta name=\"title\" content=\"(.*)\">"

Tested here using the unescaped version:

<meta name="title" content="(.*)">
Sign up to request clarification or add additional context in comments.

1 Comment

I have tried it, and got an exception. just to be sure, I have tested it on regex.powertoy.org as-well, and got a negative result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.