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 8 years ago.
Improve this question
This is some URL:
http://www.mywebsite.com/name1-name2-name3-name4-342/46547657/ca
http://www.mywebsite.com/name5-487659826/da
http://www.mywebsite.com/name6-name7-567/5677/ca
http://www.mywebsite.com/name8-name9-name10-48765766/da
http://www.mywebsite.com/name11-name12-name13-name14-name15/11117657/ca
http://www.mywebsite.com/name16-4866626/da
So, output will be:
name1-name2-name3-name4-342
name5
name6-name7-567
name8-name9-name10
name11-name12-name13-name14-name15
name16
Do you give me a regex which do that, please ?
For the given urls you have provided, you could use the following to extract the wanted substrings.
http://[^/]+/\K\w+(?:-(?!\d{4,})\w+)*
Live Demo
http://.*mywebsite\.com/(\w+(?:-(?!\d{4,})\w+)*)
Options: ^ and $ match at line breaks
Match the characters “http://” literally «http://»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the characters “mywebsite” literally «mywebsite»
Match the character “.” literally «\.»
Match the characters “com/” literally «com/»
Match the regular expression below and capture its match into backreference number 1 «(\w+(?:-(?!\d{4,})\w+)*)»
Match a single character that is a “word character” (letters, digits, etc.) «\w+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the regular expression below «(?:-(?!\d{4,})\w+)*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character “-” literally «-»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!\d{4,})»
Match a single digit 0..9 «\d{4,}»
Between 4 and unlimited times, as many times as possible, giving back as needed (greedy) «{4,}»
Match a single character that is a “word character” (letters, digits, etc.) «\w+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Created with RegexBuddy
Matches all:
http://mywebsite.com/name6-name7-567 name6-name7-567
http://mywebsite.com/name6-name7-567 name6-name7-567
http://www.mywebsite.com/name1-name2-name3-name4-342 name1-name2-name3-name4-342
http://www.mywebsite.com/name5 name5
http://www.mywebsite.com/name6-name7-567 name6-name7-567
http://www.mywebsite.com/name8-name9-name10 name8-name9-name10
http://www.mywebsite.com/name11-name12-name13-name14-name15 name11-name12-name13-name14-name15
http://www.mywebsite.com/name16 name16
Related
This question already has answers here:
Regular Expression for password validation
(6 answers)
Closed 1 year ago.
I'm new to React Native, and I need to implement new password requirements.
The new requirements are small and large letters or letters and at least one number or special character.
The requirement for the password to be at least eight characters.
Here is my code:
.matches(
/^(?=.*[a-z])(?=.*\d)(?=.*[\W_])[\w\W].+$/,
I think that should work:
((^|, )((?=.[a-z])|(?=.\d)|(?=.*[\W_])[\w\W]))+$.
This works. It requires at least one uppercase letter, one lowercase letter, one number, and one special character such as # or # or $, with a length of at least eight characters.
(?m)^((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\\W]).{8,})$
The (?m) at the beginning makes sure that the . in the regex does not match a newline.
From RegexBuddy:
^((?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[\W]).{8,})$
Options: ^ and $ match at line breaks
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match the regular expression below and capture its match into backreference number 1 «((?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[\W]).{8,})»
Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*\d)»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match a single digit 0..9 «\d»
Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*[a-z])»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match a single character in the range between “a” and “z” «[a-z]»
Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*[A-Z])»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match a single character in the range between “A” and “Z” «[A-Z]»
Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*[\W])»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match a single character that is a “non-word character” «[\W]»
Match any single character that is not a line break character «.{8,}»
Between eight and unlimited times, as many times as possible, giving back as needed (greedy) «{8,}»
Assert position at the end of a line (at the end of the string or before a line break character) «$»
It matches
abcDefg1$
1zBA^frmb
1#Basdfadsfadsf
It does not match
abcd123
123abc
abcdEFGH
abcdEFG2
abCDeF1E
1a2bc
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
How can I remove all spaces into braces with Notepad++ and RegEx?
For example:
I have string [Word1 Word2 Word3]
I need: [Word1Word2Word3]
Thanks
\s++(?=[^[]*])
\s++
matches any whitespace character (equal to [\r\n\t\f\v ])
++ Quantifier — Matches between one and unlimited times, as many times as possible, without giving back (possessive)
Positive Lookahead (?=[^[]*])
Assert that the Regex below matches
Match a single character not present in the list below [^[]*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
[ matches the character [ literally (case sensitive)
] matches the character ] literally (case sensitive)
(?:\[|\G(?!^))[^]\s]*\K\s+
Non-capturing group (?:\[|\G(?!^))
1st Alternative \[
\[ matches the character [ literally (case sensitive)
2nd Alternative \G(?!^)
\G asserts position at the end of the previous match or the start of the string for the first match
Negative Lookahead (?!^)
Assert that the Regex below does not match
^ asserts position at start of the string
Match a single character not present in the list below [^]\s]*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
] matches the character ] literally (case sensitive)
\s matches any whitespace character (equal to [\r\n\t\f\v ])
\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
\s+
matches any whitespace character (equal to [\r\n\t\f\v ])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Can someone please explain what this regexp matches?
#\b(https://exampleurl.com/)([^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#
I have no experience with regexp and I need to know what this one does.
Trying with link. It explains all:
/[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|))/
[^\s()<>]+ match a single character not present in the list below
Quantifier: Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\s match any white space character [\r\n\t\f ]
()<> a single character in the list ()<> literally (case sensitive)
(?:([\w\d]+)|([^[:punct:]\s]|)) Non-capturing group
1st Alternative: ([\w\d]+)
\( matches the character ( literally
[\w\d]+ match a single character present in the list below
Quantifier: Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\w match any word character [a-zA-Z0-9_]
\d match a digit [0-9]
\) matches the character ) literally
2nd Alternative: ([^[:punct:]\s]|)
1st Capturing group ([^[:punct:]\s]|)
1st Alternative: [^[:punct:]\s]
[^[:punct:]\s] match a single character not present in the list below
[:punct:] matches punctuation characters [POSIX]
\s match any white space character [\r\n\t\f ]
2nd Alternative: ([^[:punct:]\s]|)
1st Capturing group ([^[:punct:]\s]|)
1st Alternative: [^[:punct:]\s]
[^[:punct:]\s] match a single character not present in the list below
[:punct:] matches punctuation characters [POSIX]
\s match any white space character [\r\n\t\f ]
2nd Alternative: (null, matches any position)
I have a URL:
/ice-cream/stuff/sandwich/banana
I want to write a regular expression that ONLY matches the URL if these conditions are met:
"ice-cream" is in the URL
"sandwich" is in the URL and comes after "ice-cream"
"banana" is NOT in the URL
I tried this:
ice-cream.sandwich.^[(banana)] as well as many others but haven't found the solution.
Help is appreciate it.
Give a try to the below regex,
^(?!.*banana.*).*?ice-cream.*?sandwich.*$
OR
^(?!.*banana.*)(?:(?!sandwich).)*ice-cream.*?sandwich.*$
DEMO
Explanation:
^ Asserts that we are at the beginning of the line.
(?!.*banana.*) Negative lookahead which checks the line contain the string banana or not. If it's not then the regex engine set the marker on the starting. Or Otherwise it skips the lines which contains the string banana.
(?:(?!sandwich).)* Matches all the characters which are not of the string sandwich.
ice-cream.*?sandwich.* String sandwich must be after to the string ice-cream.
$ End of the line.
Hard to be precise without examples of matches and non-matches, but give this a try:
^(?!.*banana)(?:(?!.*sandwich(?=.*ice-cream))).*ice-cream.*sandwich.*$
Explanation of Regex:
^(?!.*banana)(?:(?!.*sandwich(?=.*ice-cream))).*ice-cream.*sandwich.*$
----------------------------------------------------------------------
^(?!.*banana)(?:(?!.*sandwich(?=.*ice-cream))).*ice-cream.*sandwich.*$
Options: Case insensitive; Exact spacing; Dot doesn't match line breaks; ^$ match at line breaks; Default line breaks
Assert position at the beginning of a line «^»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!.*banana)»
Match any single character that is NOT a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character string “banana” literally «banana»
Match the regular expression below «(?:(?!.*sandwich(?=.*ice-cream)))»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!.*sandwich(?=.*ice-cream))»
Match any single character that is NOT a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character string “sandwich” literally «sandwich»
Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*ice-cream)»
Match any single character that is NOT a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character string “ice-cream” literally «ice-cream»
Match any single character that is NOT a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character string “ice-cream” literally «ice-cream»
Match any single character that is NOT a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character string “sandwich” literally «sandwich»
Match any single character that is NOT a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Assert position at the end of a line «$»
Created with RegexBuddy
.*ice-cream.+sandwich.(?!banana).*
Try this one
I am building a RegEx that needs to find lines that have either:
DateTime.Now
or
Date.Now
But cannot have the literal "SystemDateTime" on the same line.
I started with this (DateTime\.Now|Date\.Now) but now I am stuck with where to put the "SystemDateTime"
Use this. Assuming you are not using /s modifier(or DOTALL) which takes newline characters under the dot(.)
(?!.*SystemDateTime)(DateTime\.Now|Date\.Now)
(?!.*SystemDateTime) means there is no SystemDateTime in front.
You could use negative lookahead like this:
(?!.*SystemDateTime)\bDate(?:Time)?\.Now\b
/(?!.*SystemDateTime)Date(?:Time)?\.Now/
DEMO
EXPLANATION:
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!.*SystemDateTime)»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the characters “SystemDateTime” literally «SystemDateTime»
Match the characters “Date” literally «Date»
Match the regular expression below «(?:Time)?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match the characters “Time” literally «Time»
Match the character “.” literally «\.»
Match the characters “Now” literally «Now»