Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  21] [ 6]  / answers: 1 / hits: 30659  / 11 Years ago, thu, august 1, 2013, 12:00:00

I want to test if a string can match a pattern in javascript



problem is there is a random string in the middle
pattern: account/os/some_random_string/call_back



so a string look like below will match



var mystring = account/os/1234567/call_back



thanks


More From » regex

 Answers
3

You want a regex for starts with account/os/ and ends with /call_back, here's one:



/^account/os/.*/call_back$/


.* will match any random string (including the empty string.). If you want a minimum length on the random string you change the *:



.*    : 0 or more characters
.+ : 1 or more characters
.{n,} : n or more characters (replace n with an actual number)

[#76608] Wednesday, July 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
khalidkendelld

Total Points: 55
Total Questions: 99
Total Answers: 77

Location: South Korea
Member since Tue, Feb 22, 2022
2 Years ago
;