0

What is the regular expression in powershell for reading the values between "JPEG" and "5."

JPEG_5.10.002.000.txt
JPEG_pnrl_5.10.002.000.txt
JPEG_pnrl_Explorer_5.10.002.000.txt
jpeg_fsrg_5.10.002.000.txt
JPEG_Help_5.10.002.000.txt
JPEG_5.10.002.001.txt
JPEG_pnrl_5.10.002.001.txt
JPEG_Help_5.10.002.001.txt
JPEG_pnrl_Explorer_5.10.002.002.txt
JPEG_fsrg_5.20.002.002.txt
JPEG_Help_5.20.002.002.txt
JPEG_pnrl_5.20.002.003.txt
JPEG_fsrg_5.20.002.003.txt

I used the following regex for getting the value but it is not working.What is the best pattern for getting the value between "JPEG" and "5."

$r = [regex] "[JPEG]+([a-zA-Z]+).*"
$match = $r.match("JPEG_pnrl_Explorer_5.10.002.000.txt")
$text = $match.groups[1].value
0

1 Answer 1

2

Try JPEG(.*?)5

There's no need to capture the entire string. That will capture everything up through the first 5. The ? makes it non-greedy, so it won't capture up through the last 5.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.