Regex to match URL with certain pattern [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 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

Related

Regular expression partially works [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 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

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):

Regex to get a name from parentheses without spaces [duplicate]

This question already has answers here:
Regex match entire words only
(7 answers)
Closed 4 years ago.
I'm trying to get the file name between two parentheses that can contain spaces between the name and any parentheses.
example:
( file_name )
I used the regex:
(([A-Za-z_][A-Za-z0-9_]*)[ \t]*)
The problem is that, it matches the file_name with the spaces before and after it.
I want to match the file_name without the spaces.
Any help is appreciated.
Just add \s* outside the capturing parenthesis. (also you need to escape the outermost parenthesis if you want to match a litteral parenthesis) :
\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)
You could use
\(\s*(\S+)\s*\)
and take the first group, see a demo on regex101.com.
Explained:
\( # match ( literally
\s* # zero or more whitespaces
(\S+) # capture anything not a whitespace, at least one character
\s*. # same as above
\) # match ) literally

Pattern regex substitution in Notepad++ [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 6 years ago.
Improve this question
How do I achieve this kind of regex substitution in Notepad++ & Linux / Unix Korn shell (Plain BSD Linux)?
z1.9z.01.01 Yabdadba do
da.8p.25.7p Foobar
tg.7j.75.2q Whatever
90.6q.88.zx Jane Doe
Note the char. I am not sure what you want to call it.
Substitution #1
o/p should be
Yabdadba do
Foobar
Whatever
Jane Doe
Substitution #2
o/p should be
9z Yabdadba do
8p Foobar
7j Whatever
6q Jane Doe
Substitution #3
o/p should be
z1.9z.01.01
da.8p.25.7p
tg.7j.75.2q
90.6q.88.zx
I tried using ^.* and $ with the regex option, but it won't do anything.
Using the assumption that the parts are fixed and of this form XX.XX.XX.XX
For Substitution # 1
Find (?m)^[^.\s]{2}(?:\.[^.\s]{2}){3}[^\S\r\n]+(?=\S.*)
Replace nothing
(?m) # Multi-line mode
^ # BOL
[^.\s]{2} # Four parts separated by dot's
(?: \. [^.\s]{2} ){3}
[^\S\r\n]+ # Whitespace following
(?= \S .* ) # Must be some text here
For Substitution # 2
Find (?m)^[^.\s]{2}\.([^.\s]{2})(?:\.[^.\s]{2}){2}(?=[^\S\r\n]+\S.*)
Replace ' $1 '
(?m) # Multi-line mode
^ # BOL
[^.\s]{2} # Four parts separated by dot's
\.
( [^.\s]{2} ) # (1)
(?: \. [^.\s]{2} ){2}
(?= # Whitespace following
[^\S\r\n]+
\S .* # Must be some text here
)
For Substitution # 3
Find (?m)^([^.\s]{2}(?:\.[^.\s]{2}){3})[^\S\r\n]+\S.*
Replace $1
(?m) # Multi-line mode
^ # BOL
( # (1 start), Four parts separated by dot's
[^.\s]{2}
(?: \. [^.\s]{2} ){3}
) # (1 end)
[^\S\r\n]+ # Whitespace following
\S .* # Must be some text here
^([a-z0-9]+?[.]([a-z0-9]+?)[.][a-z0-9]+?[.][a-z0-9]+?[ ]+(.+)$
Capture group 1 contains the dotted strings
Capture group 2 contains the second term of the dotted strings
Capture group 3 contains the names on the right side.
You can try at regex tester online
Since you mentioned Unix shell:
cut -f2 yourfile or awk '{print $2}' yourfile
awk -F"[\t.]" '{print $2, $5}' yourfile
cut -f1 yourfile or awk '{print $1}' yourfile
cut selects fields from files, so your first and last question demanded to select the second and first field. awk is more versatile but can be used for the same task.
Your second question asks for printing the second and fifths fields (fields separated by either tab or ".").
For notepad++ :
Substitution # 1
find = ^.*?\s+(.*?)$
repalce = \1
Substitution # 2
find = ^(\w{2})\.(\w{2})\.(\w{2})\.(\w{2})\s+(.*?)$
repalce = \2 \5
Substitution # 3
find = ^([a-z0-9.]+).*?$
repalce = \1

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