Home > Blockchain >  What will be the regex for fetching the value between two slashes where the string in the format &qu
What will be the regex for fetching the value between two slashes where the string in the format &qu

Time:02-19

Input String : Demo|15/23/xx

Output needed : Com^23

CodePudding user response:

The pattern to get text between two slashes is \/([^/] )\/

import re

s = "Demo|15/23/xx"
match = re.findall(r"\/([^/] )\/", s)[0]  # 23
result = f"Com^{match}"  # Com^23

CodePudding user response:

/(?<=\/).*(?=\/)/gm will match whatever is between two '/'.

Then you will have to use any print function.

# python
    pattern = r'(?<=\/).*(?=\/)'
    text = "Demo|15/23/xx"
    answer = re.findall(pattern, text)[0]
    print(f"Com^{answer}")

pattern = /(?<=\/).*(?=\/)/gm
text = "Demo|15/23/xx"
answer = pattern.exec(text)
console.log("Com^" answer)

  • Related