Match multiple strings with one regex - regex

My regex is just matching the first string it matches but I want to match more (all of them)
My regex: https://regex101.com/r/t4g2ae/1 (link to the problem)
(\d+\.\d+)\s*(ha|m²)
I was expecting matching more strings

Related

Regex to match list of numbers inside matching group

I am trying to build a regular expression, to match a list of numbers inside an html tag.
The tag is data-p="and the content is here".
Inside the content there is a list of numbers formatted like this:
["16834091899728893939","8871244709062187521","3716487480481705970","1266937738203421917"]
I would like the regex to return the list of digits: [16834091899728893939, 8871244709062187521, 3716487480481705970, 1266937738203421917]
Is it possible to match a list inside an already matched group?
It is easy to match content of all data-p's tags from the whole page: "data-p="(.*?)"", but I cannot get the list f numbers from inside.
Is it possible to do al in one regex?
Thanks !
Full html below
data-p="%.#.null,null,null,null,null,null,[8,null,["oyo rooms gurgaon",[null,null,null,"INR",[[2023,1,27],[2023,1,28],1,null,0],null,[],[],null,null,null,null,null,null,null,null,null,null,null,null,[[[353,null,true],[]]],null,null,null,[],null,null,null,[],null,null,null,null,[],null,null,null,null,null,null,null,null,null,null,[]],[null,["16834091899728893939","8871244709062187521","3716487480481705970","1266937738203421917"],null,null,null,null,1,1,3,null,null,null,null,null,[],null,null,null,null,"Gurugram, Haryana",null,null,null,null,null,null,null,null,null,null,null,null,"oyo rooms gurgaon",null,[false]],0,null,null,0,null,false,null,null,false,null,null,null,null,null,[[[1],[3,[null,true]],[5,[null,true]],[4,[null,true]],[6],[7],[8]],false]],null,null,null,null,null,2]]"
It depends on which regex engine you are using. For example, using the PCRE engine you can construct the following regex:
(?:data-p="[^"]*?\[|\G,)"(\d+)"
Here is the demo.
This expression match a "(\d+)" string under two conditions: it should either be preceded by data-p="[^"]*?\[ pattern, or it should be preceded by \G, pattern. The first pattern is obvious. The second one includes \G to match the position of the previous match. This disables matching the "(\d+)" after every comma. In the demo above it disables matching of the string 456 in the other-tag.

Regular Expression match only beginning of string

I'm trying to match a regular expression on a string that has multiple matches, but i want to match the first occurrence and i'm expecting my match only in the beginning of the string
E.g.: 4_12052022_01.abc
in the above "4" is my target for a match.
But my string can also have something like 1_231233_4_43.abc, so here it should not match the occurrence of 4 because it's not in the beginning of the string.
I'm using SyncbackPro v9 and want to setup filtering through regex.
What i have tried and doesn't seem to work for me
4_.*, this matches both the strings above
^4_.*, this tests fine in most of the online regular testing websites, but in syncback it doesn't work.

Regex for non-title-casing with nordic chars (ÆØÅæøå)

I am encountering some issues with a regex that should match all non-title-case strings. The problem is that it matches all sentences containing the nordic characters ÆØÅæøå (at least when I run it through https://www.regex101.com/).
\b([ÆØÅA-Z])([ÆØÅA-Z][ÆØÅA-Zæøåa-z]*)|\b([æøåa-z])([æøåa-zÆØÅA-Z]+)
It should match strings like:
"RØDOVRE"
It should NOT match strings like:
"Rødovre"
You could use this expression:
(?:(?<=\s)|^)([ÆØÅA-Z]+)(?:(?=\s)|$)
Here is a Demo

RegEx matching standalone string with dashes

I need to write a RegEx to match the "1-234-5678" string if there are no dash characters around it.
I have the following RegEx:
\b\d\-\d{3}\-\d{4}\b
Now this works fine and matches "1-234-5678" correctly in the strings below:
text 1-234-5678 text
111 1-234-5678 1212
The RegEx also correctly NOT matches "1-234-5678" in the strings below:
text1-234-5678text
1111-234-56781212
But the problem is that it also matches in the following strings:
text-1-234-5678-text
111-1-234-5678-1212
It's because \b matches before and after the dashes.
How can I eliminate matches if there's a dash in front or after the data?
Use a negative lookbehind and negative lookahead to check whether the above mentioned format is not preceded and followed by a - symbol,
(?<!-)\b\d\-\d{3}\-\d{4}\b(?!-)
DEMO

regex pattern selects alternates matches

Regex pattern
/("[^:=,]+":")(.*?)("}*\]*}*,")/
String :
"foo":""fooooooooooooooooooo"foooo","bar":"barrrrrrrrr""barrrrrr","fooo":"foooooo","bar":"barrrrrr","
Matches the first and the third pattern
http://rubular.com/r/S5fbsSfCjy
String:
"bar":"barrrrrrrrr""barrrrrr","fooo":"foooooo","bar":"barrrrrr","foo":""fooooooooooooooooooo"foooo","
Matches the first and the third pattern
http://rubular.com/r/hDfcBCkB2o
How do make it match all 4 patterns match any of the string above?
That's because the ," at the end of your regex pattern consumes the quotes from the following string. So, it is not matched. In fact, the regex will match only every alternate matching string.
You need to use look-ahead:
/("[^:=,]+":")(.*?)("}*\]*}*(?=,"))/
http://rubular.com/r/6v2OjPtmVM