Regular expression partially works [closed] - regex

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
I have the regex
(?:(\(\n\s*\[)|(?:,\[))(?<field>.*?)\]\s*(?<properties>.*\n.)
I get the field name and values, but my regex not working if new line.
It's here my regex and text https://regex101.com/r/5o3o1f/1
For example

This works fine (?<=[\r\n,])\[(?<fieldName>.*?)\]\s*(.*?)(,|([)])$).

If the NULL is indicator of the end of properties you can use it and if it spans
lines just insert some optional whitespace,
This one is refactored and does whitespace trim.
(?:\(\s*|,)\[(?<field>.*?)\]\s*(?<properties>[\s\S]*?)\s*N\s*U\s*L\s*L
https://regex101.com/r/IwkOdr/1
(?: \( \s* | , )
\[
(?<field> .*? ) # (1)
\] \s*
(?<properties> [\s\S]*? ) # (2)
\s* N \s* U \s* L \s* L

Related

notepad++ line combine [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We have this line order
129
12
2020
5424180606943758
we need to be this way
5424180606943758|12|2020|129
how to do this in notepad ++ or in onoter app
Ctrl+H
Find what: (\d+)\R(\d+)\R(\d+)\R(\d+)\R?
Replace with: $4|$3|$2|$1
CHECK Wrap around
CHECK Regular expression
Replace all
Explanation:
(\d+) # group 1, 1 or more digits
\R # any kind of linebreak
(\d+) # group 2, 1 or more digits
\R # any kind of linebreak
(\d+) # group 3, 1 or more digits
\R # any kind of linebreak
(\d+) # group 4, 1 or more digits
\R # any kind of linebreak, optional
Replacement:
$4 # content of group 4
| # a pipe
$3 # content of group 3
| # a pipe
$2 # content of group 2
| # a pipe
$1 # content of group 1
Screenshot (before):
Screenshot (after):

How to make regex only allow one character after a negative lookahead [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want regex to parse for four digits, with only one comma or nothing after those digits being considered valid.
Valid examples:
1970
1970 hello
1970, hello
hello ,1970
Invalid examples:
1970hello
1970,hello
1970,,
hello,1970
I only want the digits (e.g. 1970) to actually be parsed.
I currently have: (?<![^\s,])(\d{4})(?![^\s,]), but that matches with the bottom three invalid strings. Any ideas?
If you want only one comma or nothing after the 4 digits, you could use a positive lookahead (?=,?(?!\S)) asserting what is on the right is an optional comma. Then use a negative lookahead to assert what comes after the comma is not a non whitespace char.
If what comes before the 4 digits can only be a comma, but not a not whitespace char before that comma, you can use a negative lookbehind (?<!\S\S) to exclude 2 consecutive non whitespace chars
But you also want to exclude matching not a comma before (?<![^,\s]) to for example not allow $1970
(?<!\S\S)(?<![^,\s])\d{4}(?=,?(?!\S))
(?<! Negative lookbehind, assert what is on the left is not
\S\S Match 2 consecutive non whitespace chars
) Close lookbehind
(?<! Negative lookbehind, assert what is on the left is not
[^,\s] Match any char except , or a whitespace char
) Close lookbehind
\d{4} Match 4 digits
(?= Positive lookahead, assert what is on the right is
,?(?!\S) Match an optional , not followed by a non whitespace char
) Close lookahead
Regex demo
Note that if you need the match only you can omit the capturing group.
Your articulation of the conditions doesn't seem to agree with your examples. One possible and plausible generalization from your examples would be require the number to be space-separated, but permit a single adjacent comma before or after the number but of course, we can't really know if that's what you actually mean.
(?:(?:^|\s),?)(\d{4})(?=,?(?:\s|$))
The capturing parentheses contain the number; there will be a non-capturing match before it.
Because ur comma. You need (?<!\S\S)(\d{4})(?!\S\S) to match invalid.

What does this (\(\d\d\d\)\s)? regex match? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
What does this ((\d\d\d)\s)? regex match?
\d matches the digits. it is all about the langugae you are using.
In python3, [0-9] matches only 0123456789 characters, while \d matches [0-9] and other digit characters, for example Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩.
\s matches any whitespace character
\d matches digits from [0-9].
\s matches white-space characters like [ \t\n\r]
? is means optional, it matches even if the following regex are not present.
() are used for grouping.
Now the question is what does ((\d\d\d)\s)? match?
\d\d\d matches 3 consecutive digits and group them to $1.
((\d\d\d)\s) matches 3 consecutive followed by space and this is grouped to $2.
since we have ? at the end of the regex, it matches digits followed with space and also if there are no such match.
In case if there is no match, it points to start of the line.
The regex expression :
The first backslash escapes the open parenthesis that follows, as it is a special character, so the regex will search for an open and a close parenthesis in the input string
Example : (111)
have a look at this site
https://regex101.com/r/yS5fU8/2
1st Capturing Group (\d\d\d)
p (\d\d\d) \d matches a digit (equal to [0-9])
\d matches a digit (equal to [0-9])
\d matches a digit (equal to [0-9])
\d matches a digit (equal to [0-9])
and
- \s matches any whitespace character (equal to [\r\n\t\f\v ])

Regex to match URL with certain pattern [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
$pattern = '/<a\s+href=["\']([^"\']+)["\']/i';
$desc_feed = preg_replace($pattern, '<a href="https://www.facebook.com/something"', $block->get_description());
This is the regex I use to filter for URL which works well. However, I just want to target a certain type of URL, namely I just want to replace the entire URL ONLY if it contains a certain substring: //l.face... (without the dots)
any help appreciated.
Disclaimer: Don't parse html with regex !!
But, if you have too, this might work for your test case.
Find: '~(?s)<a\s+href=(["\'])(?:(?!\1).)*?//l\.face(?:(?!\1).)*?\1~'
Replace: whatever you want
(?s) # Dot all
<a \s+ href=
( ["'] ) # (1), Delimiter
(?:
(?! \1 ) # Any char except delimiter
.
)*?
//l \. face # What you're looking for
(?:
(?! \1 ) # Any char except delimiter
.
)*?
\1 # Backref to delimiter

RegEx replace all after and all before [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a file with about 2000 lines and the columns are divided with ,.
I need to replace all dots ., that are after the 10th comma , with a comma. However, I do not replace any dots that are before that 10th comma on each line.
How can I make it replace all dots after the 10th comma with commas?
Find what:
(^(?:[^,\n]*,){10}[^.\n]*|(?!^)\G[^.\n]*).
Replace with:
$1,
Place the cursor at the beginning of the line. Then Replace All.
Explanation
( # Capturing group 1, whatever that stays the same
^(?:[^,\n]*,){10}[^.\n]* # From the beginning of the line, skip 10 columns
# (with 10 commas), then skip to the nearest dot
| # OR
(?!^)\G[^.\n]* # Continue from where the last dot matches
# and skip to the nearest dot
)
. # Dot, to be replaced
I would use this regex:
(?:^(?:[^\R,]*,){10}|(?!^)\G)[^\R.]*\K\.
And replace with ,.
Are you sure it's notepad++ v4.6? That version is pretty old and unfortunately, its regex capabilities won't support the above. The above works on v6.1.
(?: # Beginning of non-capture group
^ # Match only at the start of the string
(?: # Beginning of non-capture group
[^\R,]* # Match non-newlines and non-comma characters
, # Match commas
){10} # Close of non-capture group and repeat 10 times
| # OR
(?!^)\G # A \G anchor that is not at the start to match from previous matches
) # Close of non-capture group
[^\R.]* # Match non-newlines and non-dot characters
\K # Reset the matching
\. # Match a dot