I have looked everywhere but I am stuck and need some help.
I believe I need a regex to replace a quote "
(for inches) at the end of a number.
For example 21.5"
with 21.5inch
I need to do it only if the "
has a number before it.
Thanks in advance!
Asked
Active
Viewed 81 times
0

MaxZoom
- 7,619
- 5
- 28
- 44

Chris Mitchell-Clare
- 11
- 2
-
Are there possible whitespaces between the number and quote? – hwnd Aug 07 '15 at 02:06
-
Corrected sentences to make problem more clear and highlighted special characters. – MaxZoom Aug 07 '15 at 02:33
3 Answers
1
-
1Wrong! `\d` does not includes decimal notation `.` Also, it does not forgive space between digit and `"`. – Haywire Aug 07 '15 at 02:39
-
-
-
-
1
-
@haywire you need to look at how the substitution is being used at the bottom of the demo. – chris85 Aug 07 '15 at 03:45
-
0
Try this:
(?<=\d)"
https://regex101.com/r/lC9tZ7/2
It should grab the " as long as it follows a digit.
If it can have spaces between the digit and ", try this:
(?<=\d)\s*"

lintmouse
- 5,079
- 8
- 38
- 54
0
Try (\d+\.{0,1}\d+)\s*"
Explanation: Lets try matching 21.54 inch
\d+
matches21
\.{0,1}
escapes decimal notation and matches if there's a.
atleast 0 times (i.e., there is no decimal at all) and atmost 1 times (i.e., a number can only have at most 1 decimal). So, we have so far matched21.
\d+
matches the remaining54
. So far matched21.54
\s*
forgives if there is any space followed by the number"
finally ensures that the number is followed by the inch notation.
Check this demo link here.

Haywire
- 858
- 3
- 14
- 30
-
You can safely omit `\s*` if there should not be any space between the number and `"` – Haywire Aug 07 '15 at 02:58
-
1