Regex for text between items [duplicate] - regex

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I'm having a hard time pulling out just the 1069 value using regex. I think I might be trying to use unsupported features to make it worse.
Q1: Would someone be able to let me know what regex would be needed to pull the numbers the 4th and 5th colons (value of 1069)
Q2: How to pull the items after the 6th colon? (value of 2929)
sample text:
diamond:dev:liquid:beta:1069:zone:2929

Answer 1: How to get value between 4th and 5th colons:
(?>[^:]+:){4}([^:]+)
Try at regex101
Answer 2: How to get value after the 6th colon:
(?>[^:]+:){6}([^:]+)
Try at regex101
Note: You can replace + with * to handle cases like ::::2: (empty between colons).

Related

Postgresql regex replace numbers to asterisks [duplicate]

This question already has answers here:
Regex to mask characters except first two and last two characters in Java
(4 answers)
Closed 5 months ago.
I use Postgresql and need to replace numbers to asterisk at database layer. Howerver I'm new to learn regex and seems to be hard to do this with my current knowledge.
I will have in my database 16 numbers varchar and I need to replace middle numbers with asterisk.
Example.
123467812345678 -> 12**********5678
Could someone tell me how regex for this should look like in postgresql ?
Thanks in advance
Thanks to #Wiktor Stribiżew:
SELECT regexp_replace('123467812345678', '(?<=..).(?=....)', '*','g');

Regex Extract on Google Sheets [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I am trying to find an expression that can be used extract a string after a specific number of characters.
E.g
FR_EN_BR_Student_Exact
FR_EN_NB_Student_Exact
I would want a pattern that can take all characters past the second underscore ( not including the underscore.
Would appreciate any ideas!
I understand basic regex but am having trouble with this specific query.
try:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(A1:A, ".+_.+_(.+_.+_.+)")))

Select the second instance of a character with regex [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I want to select the second 'M' in the following string using regex.
So, the M after T.
P3Y6M4DT12H30M5S
Sometimes the string looks like one of these:
PT12H30M5S
PT12H30M5.234523S
I've tried multiple expressions and searched for a similar case but couldn't find anything.
Could someone help me build an expression to select the M after T so I can use it in my regex replace function?
(?!.+T.+)(M)
Selects everything until the first T and then selects everything until the first M and captures it.
Example: https://regex101.com/r/sPbQQj/2

Find two QnA maker link handler and assign each found regex an html <a> tag [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 3 years ago.
I want a regex for the following string:
For more: [Click here](https://www.google.ca) and [click me](https://www.google.com)
For that My current regex is as follows.
/\[.*\]\((((https?\:\/\/)|(www\.))(\S+))/ig
Give me the regex with that I can find two different links in the same line.
Right now I am finding 1 combined regex for both of them.
My guess is that we have URLs in (), which we can use an expression similar to, if that'd be the case:
\((https?[^\s]+)\)
with a capturing group, where our desired outputs are.
Demo 1
For capturing the [], we would just expand our expression:
(\[.+?])\((https?[^\s]+)\) //$ sign removed
Demo 2

creating a regex that captures these rules [duplicate]

This question already has answers here:
Regex to validate password strength
(11 answers)
Closed 7 years ago.
I have the following password requirements I'm trying to express in a regex expression and I'm struggling. Any help appreciated!
Passwords must contain characters from 3 of the following 4 types:
upper case letters
lower case letters
numerals
special characters
I've found some similar examples and if my knowledge of regex was stronger I could figure it out but I haven't found one that has the "3 of 4" requirement.
Edit:
Ok here is what I'm using for now, I'm currently testing it. Does this look right?
passwordStrengthRegularExpression="(?=^[^\s]{8,}$)((?=.?\d)(?=.?[A-Z])(?=.?[a-z])|(?=.?\d)(?=(.\W){1,})(?=.?[a-z])|(?=(.\W){1,})(?=.?[A-Z])(?=.?[a-z])|(?=.?\d)(?=.?[A-Z])(?=(.\W){1,}))^.*"
Analog to https://stackoverflow.com/a/5142164/2606322 I would do the following for all 4 requirements
^(?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8}$
and then add the other 4 (3 of 4) possibilities or-ed together like
^
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9]).{8})|
$
just in one line. Ugly but might work. And, of course, replace the !##$&* with the set of your liking.