Email Masking..
Sample input :- Testuser#gmail.com
Sample output :- T******r#g***.com
First letter of username, 6 asterisks, last letter of username, # character, first letter of domain, 3 asterisks,then extension.
what is the regex expression for this?
I need the code like the way below,
String Email= Email.replaceAll("(?<=.).(?=[^#]*?#)", "*");
Here is a possible Javascript solution
var email = "Testuser#gmail.com"
var re1 = /(?<=[A-Za-z0-9]).+(?=[A-Za-z0-9]\#)/ // Replaces username with "******"
var re2 = /(?<=\#[A-Za-z0-9]).+(?=\.com)/ // Replaces domain with "***"
var modemail = email.replace(re1, "******").replace(re2, "***")
Related
How do I use the re.sub python method to append +1 to a phone number?
When I use the following function it changes this string "802-867-5309" to this string "+1+15309". I'm trying to get this string "+1-802-867-5309". The examples in the docs replace show how to replace the entire string I don't want to replace the entire string just append a +1
import re
def transform_record(record):
new_record = re.sub("[0-9]+-","+1", record)
return new_record
print(transform_record("Some sample text 802-867-5309 some more sample text here"))
If you can match your phone numbers with a pattern you may refer to the match value using \g<0> backreference in the replacement.
So, taking the simplest pattern like \d+-\d+-\d+ that matches your phone number, you may use
new_record = re.sub(r"\d+-\d+-\d+", r"+1-\g<0>", record)
See the regex demo. See more ideas on how to match phone numbers at Find phone numbers in python script.
See the Python demo:
import re
def transform_record(record):
new_record = re.sub(r"\d+-\d+-\d+", r"+1-\g<0>", record)
return new_record
print(transform_record("Some sample text 802-867-5309 some more sample text here"))
# => Some sample text +1-802-867-5309 some more sample text here
You can try this:
new_record = re.sub(r"\d+-[\d+-]+", r"+1-\g<0>", record)
Kapil Arora <kapil.arora#abc.in>
How to find the name before angular bracket
This is the RegEx I used ([^<]+). but it is not finding first String
I would just add a start of input anchor ^ to the head of your expression, plus a look ahead for a space so you get just the name (no trailing space):
^[^<]+(?= )
No need for brackets; group 0 is the whole match, which is what you want.
See live demo.
Since you haven't specified any language. I would be solving in JavaScript.
Lets assume an email id as "kapil.sharma123#gmail.com".
Thus the program would be something like this:
var email = "kapil.sharma123#gmail.com";
var regex = /(^[A-Za-z]+\.+[A-Za-z]+)/;
var res = email.match(regex)[1];
res = res.split(".").join(" ");
Here I am matching the regex with the email id string and then extracting from the first index.
Finally I am spliting on "." and joining with a blankspace.
Note : It also works for simple email ids like "kapil.sharma#gmail.com"
You may try this:
const regex = /^\s*([^<]+)\s*</g;
const str = `Kapil Arora <kapil.arora#abc.in> bla bla bla <asadfasdf>`;
var match = regex.exec(str);
console.log(match[1].trim());
applying the below regex on below email body:
(pls[a-zA-Z0-9 .*-]*) \(([A-Z 0-9]*)\)
email body:
pls18244a.lam64*fra-pth (PI000581)
pls18856a.10ge*fra-pth (PI0005AW)
pls25040a.10ge*fra-pth (IIE0004WK)
pls27477a.10ge*fra-pth (WL050814)
pls22099a.stm4*par-pth (PI0005TE)
returns 5 match, with two groups. what is the VBA script to get groups in each match using using incremental variable to copy each match groups in excel row?
Not making any changes to your regular expression pattern. Using the following way, you can iterate through the groups of each match:
str="pls18244a.lam64*fra-pth (PI000581)pls18856a.10ge*fra-pth (PI0005AW)pls25040a.10ge*fra-pth (IIE0004WK)pls27477a.10ge*fra-pth (WL050814)pls22099a.stm4*par-pth (PI0005TE)"
Set objReg = New RegExp
objReg.IgnoreCase=False
objReg.Global=True
objReg.Pattern = "(pls[a-zA-Z0-9 .*-]*) \(([A-Z 0-9]*)\)"
Set objMatches = objReg.Execute(str)
For Each match In objMatches 'The variable match will contain the full match
a= match.Submatches.Count 'total number of groups in the full match
For i=0 To a-1
MsgBox match.Submatches.Item(i) 'display each group
Next
Next
Set objReg = Nothing
I was unable to find correct regex for my case. I found almost perfect, but it still passes with leading spaces.
Requirements:
var regex = /^\s*(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)\s*$/;
var passwd = "abcdefg12345" //Passes
var passwd = " abcdefg12345" //Does not pass
var passwd = "abcdefg 12345" //Does not pass
var passwd = "abcdefg12345 " //Passes but should not
Any advise?
Also I would like to add minimum requirement for length, how should that be done?
If you want to prevent leading or trailing spaces, just remove the last \s. To set a minimum length for the password, change your + quantifier to {n,}, where n is the minimum length.
For example, the following pattern matches any sequence of 5 or more alphanumeric characters that contains at least one letter, and at least one number:
/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]{5,})$/
I need a little assistants with my poor regex chops. I am trying to grab the 41398 from the URL. This number is a variable
http://www.website.com/beta/flips/index/41398_1363874140/friend/756
I figured out how to grab everything up to the / after index.
var url = document.URL;
var myRegexp = /index(.*)/;
var match = myRegexp.exec(url);
this leaves me with /41398_1363874140/friend/756....
Is there a solution with regEx to grab the number between / and _ ?
I tried
var url = document.URL;
var myRegexp = \/(.*?)\_;
var match = myRegexp.exec(url);
and of course the '/' is the issue.
If you know there will always be an underscore you can use:
var url = document.URL;
var myRegexp = /\d+_/;
var match = myRegexp.exec(url);
Do you need the first match? If not, then you can directly use:
var url = document.URL;
var myRegexp = /index\/(.*?)_/;
var match = myRegexp.exec(url);
Well, you were almost close. Underscores do not need to be escaped.
Otherwise, you could use your first match (adding those after your first 3 lines of code above):
var myNewRegexp = /\/(.*?)_/;
var NewMatch = myNewRegexp.exec(match);
You can use:
/\/index\/(\d+)/
which means the first group matches the number.
Here is a regex that matches just the number (?<=index/)[0-9]*(?=_). You didn't say what language you are working in so that would help make this more specific