Regular:

\[A-za-z]{2,}.1cws\ 

The text I want to catch is bold: http: // SomeAdress / SomeAdress / ws / Testws .1cws? Wsdl

http://regexr.com/3f2db

  • What language do you need to work? - VenZell
  • VisualBasicScript - Sergey Ser

2 answers 2

With the help of advanced and retrospective verification, you can achieve what you want:

 /(?<=\/)([A-za-z]{2,})(?=.1cws)/ 

(?<=\/) - checks if the / character is found before the specified expression.
(?=.1cws) - checks if the character set .1cws occurs after the specified expression.

View an example of work: https://regex101.com/r/0Nv9gh/1 .
It will work in languages ​​with PCRE support. In JS there is no retrospective verification.

Expressions inside the forward and retrospective test are not captured in the result set. You can read more about these checks in the article " Leading and Retrospective Checks in Regular Expressions ".


Since JS does not support retrospective checks, you can capture the characters of interest into a separate group and work with it already:

 /\/([A-za-z]{2,}).1cws/ 

View an example of work: https://regex101.com/r/josgHv/1 .

  • @ SergeySer, you are exaggerating. Practical tasks, the answers here to questions, the need for work. Read here a couple of articles: phpclub.ru/detail/article/regexp_1 and phpclub.ru/detail/article/regexp_2 . They will help you deal with regulars. If my answer helped you, vote for it and mark it correct. - VenZell
  • Alas, the implementation apparently does not support this. (PCRE). With such a pattern RegExp does not pass the test - Sergey Ser

To solve my question, you need to add a "positive look-ahead" construction to the end of the template.

Note: look-behind expressions are not supported in some implementations, for example in javascript

 [A-za-z]{2,})(?=.1cws)