You need a regular expression that will search for everything that starts with / and ends with numbers. Wrote this option, but it does not work:

/ ^ / $ [0-9] + /

  • we need to escape the character / in the regular form, something like this: /^\/[0-9]+/$ . Only select lines /123 , but not /asd123 . If you need the latter, then /^\/.*[0-9]+/$ - BOPOH
  • In regulars I am weak (I need the last option, tried to put this expression, I get the error: Unknown modifier '$' - Filipp Mustang
  • one
    Well, yes, I was sealed, $ is the end of the line, and it should be inside the regular schedule, i.e. inside /.../ , i.e. should have been like this: /^\/.*[0-9]+$/ . I have designed the examples by reference, i.e. you could just watch and try the work of the regular online - BOPOH
  • Another problem has arisen, the text I need is not the beginning and the end. That is, you need to pull this element out of the line. - Filipp Mustang
  • then it suffices to remove the symbols of beginning and end, i.e. ^ and $ . And how to choose? For example, there is the text /asd123/dsa123asd321 - what should be the result? heap options: whole line, only /asd123 and /dsa123 (or /dsa123asd321 ) or only /dsa123 or something else - BOPOH

1 answer 1

here is my version ^\/+.+[0-9]+$ . ^\/+.+[0-9]+$ . you can check here

if the desired value in the text, you can use this option \/+.+[0-9]

 $re = "/\/+.+[0-9]/"; $str = "sadsadas/dfsdf222dfsdfsf7131s2dasdsadasdasda\n"; preg_match($re, $str, $matches); 

We /dfsdf222dfsdfsf7131s2 : /dfsdf222dfsdfsf7131s2