Postgresql regex replace numbers to asterisks [duplicate] - regex

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');

Related

Redshift regexp_replace Non-English Standard characters [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
In redshift, I'm trying to to regexp_replace strings like the following example to maintain apostrophes, spaces, alphanumeric, but remove non-english-standard characters like Â. Is this possible?
'He's interested in addressing the challenges of #energy &  #climate change'
to
'He's interested in addressing the challenges of energy climate change'
Use /[^\x00-\x7F]/g for non-ASCII characters.

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, ".+_.+_(.+_.+_.+)")))

Regex help to filter only 720p [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 4 years ago.
I'd like to setup auto download of some Anime using an RSS feed, but only 720p versions. The format never changes and it always looks like below.
[Blahblah] Blahepisode - 12 [720p].mkv
Here is the regex I have come up with but cannot get to work properly.
/.\+[720p]+/g
Any help would be appreciated!
Assuming you have lines that look like your example, it will be mached with the following Regex:
.+(?:\[720p\].mkv)
It maches one or more chacacters at start, followed by '[720p].mkv'.
Note that the Square brackets are escaped to '\[' and '\]', otherwise they have special meaning.
if you only need '[720p]' then you can use:
\[720p\]

Matching multiple occurrences with regex [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'm building an extractor in Graylog to pull tac_plus syslog data.
I have a log:
<70>Oct 13 10:10:05 auth tac_plus[17354]: 2015-10-13 10:10:05 -0500#01110.10.89.1#011jmartinez#011tty132#01110.10.1.27#011stop#011task_id=146#011timezone=CDT#011service=shell#011start_time=1444747732#011priv-lvl=15#011cmd=show running-config <cr>
I want to extract the indvidual statements between the #011 markers. I was able to get the first section, the IP with:
(?<=#011)(.*?)(?=#011)
Now I want to extract the 'jmartinez'. I'm trying:
#011.*?#011(.*)(#011)
but it matches:
jmartinez#011tty132#01110.10.1.27#011stop#011task_id=146#011timezone=CDT#011service=shell#011start_time=1444747732#011priv-lvl=15
if i do:
#011.*?#011(.*)(#011tty)
it seems to work but i'd rather it not rely on seeing #011tty because it might be something else in another message.
what about the next one? how can I extract tty132, 10.10.1.27, stop, task_id=146, etc
any help would be greatly appreciated!
The simple answer is to use a reluctant quantifier (just like your working IP capture):
#011.*?#011(.*?)#011
But I would go further and capture all groups at once, eg:
#011(.*?)#011(.*?)#011(.*?)#011(.*?)#011(.*?)#011(.*?)#011

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.