Reputation: 809
I have this line :
"Internal": "128 6GB RAM, 128 8GB RAM"
and I wanted to get only the first 6GB RAM
so I tried this :
^(\dGB RAM)
that doesn't match anything, if I removes the ^()
it matches all the 6GB RAM
& 8GB RAM
.
I tried it on https://regexr.com/ website
Upvotes: 0
Views: 38
Reputation: 9928
/\dGB RAM/g
with the flag g
(global) will match 6GB RAM
and 8GB RAM
/\dGB RAM/
without the g flag will only match 6GB RAM
You saw it matched both 6GB RAM
and 8GB RAM
because regexr.com adds global flag as default, turn it off and you'll only see it matches 6GB RAM
.
Upvotes: 1
Reputation: 3281
I absolutely hate regex, so you can do something like this:
first_ram = internal.split(",")[0]
Upvotes: 0