I'm trying to capture a value within some strings in JavaScript.
These are the possible strings:
http://www.url.com/sw/standard_b.jpg
http://www.url.com/sw/2_1238144910_3655223_ih_ee2.jpg
http://www.url.com/sw/2_1238144910_3655223_c_yr8.jpg
http://www.url.com/sw/56_1238193910_320_kh.jpg
I'm trying to write a regex to capture the following values from each string:
b
ih
c
kh
Every regex I write only captures these 1 character backreferences:
b
c
I can't figure out the regex that will capture the values above from the strings above.
The closest I got was this:
Code:
/(.+)([a|b|c|ih|kh])(.*)?(\.jpg)/i
It captures the value of "b," for example, in all the strings, but the moment I try to capture the value of "ih" or "ah" in the possible string sequences, it simply cuts off the second character and only returns "i" (from ih) or "k" (from kh).
I'm really stumped. The major problems occurs when the value to capture is longer than 1 character (as in ih|kh opposed to a|b|c).
All insight or solutions will be appreciated.