Reputation: 89
I am trying to match a string with a java regex and I cannot succeed. I'm pretty new to java and with most of my experience being linux based regex, I've had no success. Can someone help me?
Below are the codes that Im using.
The regex is-
//vod//final\_\d{0,99}.\d{0,99}\\-Frag\d{0,99}
The line that I'm trying to match is
/vod/final_1.3Seg1-Frag1
where I want 1.3, 1 and 1 to be wildcarded.
Someone please help me out... :(
Upvotes: 0
Views: 171
Reputation: 382
Does this work?
/\/vod\/final\_\d{0,99}.\d{0,99}Seg\d-Frag\d{0,99}
Also, here's what I used to edit the regex you provided above: http://rubular.com/
It says it's for ruby, but it also mentions that it works for java too.
Upvotes: 0
Reputation: 63359
You are missing the Seg1
part. Also you are escaping characters that need not to be escaped. Try out this regexp: /vod/final_\\d+\\.\\d+Seg1-Frag\\d+
Upvotes: 2
Reputation: 328556
This should work:
Pattern p = Pattern.compile( "/vod/final_\\d+\\.\\d+Seg\\d+-Frag\\d+" );
Notes: To protect special characters, you can use Pattern.quote()
When running into problems like this, start with a simple text and pattern and build from there. I.e. first try to match /
, then /vod/
, then /vod/final_1
, etc.
Upvotes: 2
Reputation: 7957
You're escaping too much. Don't escape /, _, -.
Something like:
/vod/final_\d{0,99}.\d{0,99}-Frag\d{0,99}
Upvotes: 0