This question already has an answer here:
I need get "v3.4.2" in string by regex php. String: "ABCDEF v3.4.2 GHI KLMN";
</div>
This question already has an answer here:
I need get "v3.4.2" in string by regex php. String: "ABCDEF v3.4.2 GHI KLMN";
</div>
A safe RegEx to work with variable lengths and digits:
\bv(\d+\.)+\d+\b
<kbd>Live Demo on Regex101</kbd>
How it works:
\b # Word Boundary
v # v
(\d+\.) # Digit(s) followed by . - i.e. 3. or 4.
+ # Match many digit(s) followed by dot - i.e. 3.4.2. or 5.6.
\d+ # Final digit of version (not included above because it has no trailing .)
\b # Word Boundary
If the format is exactly as shown, use this shorter RegEx:
\bv\d\.\d\.\d\b
<kbd>Live Demo on Regex101</kbd>
\b
marks a word boundary, so it will not capture inside donotv3.4.2capturethis
How it works:
\b # Word Boundary
v # v
\d\.\d\.\d # 3.4.2
\b # Word Boundary