Dear experts, are there any specials in regular expressions? signal to calculate the found values? For an example on the screen, to return 3. To calculate on the side of a long line is not suitable for my case, it is of interest to do just this with the help of regulars 
- oneThe length of the match found is easy to get using code. A regular expression helps to find the text, but they never return its length. - Wiktor Stribiżew
- oneTell me how to hammer a nail with a microscope. The hammer is not suitable for my case, it is of interest to do this with a microscope. - Xander
- In the case of a microscope, there is still some chance. And there is no. - Wiktor Stribiżew
|
1 answer
Well, using Python, for example, you can do it like this:
import re result = re.search(r'Aut', 'elit Autee') print(result.span()[1] - result.span()[0]) Also, since we find substrings, the length of this substring will be the length of the found entry:
import re result = re.findall(r'aut', 'Aut gravis elit, aut simple elit', re.IGNORECASE) for i in result: print(len(i)) And here is a better example:
result = re.findall(r'\b\d+\b', '1231 12вы 12ы3 345123 65712 1ф2 45345345 234выа 234') for i in result: print(len(i)) Regular expressions themselves do not retain length. The maximum that they contain: the starting and ending indices relative to the source row.
|