Regex String URL [closed] - javascript

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
Example
1. http://ad.ly/123411/http://blabalba.com/adaf
2. http://ad.ly/142145/http://blabal.com/adf34
how to replace front String http://ad.ly/1246721/ use js regex
into http://blabalbal.com/adaf
get this http://blabalbal.com/adaf

The regexp required is http:\/\/adf_.ly\/\d+\/(.+)
var str = 'http://adf_.ly/1246721/http://prefiles.com/files';
var re = /http:\/\/adf_.ly\/\d+\/(.+)/;
var newstr = re.exec(str)[1];

You can just take the part you're interested in using lookahead directive:
s = 'http://adf_.ly/123411/http://blabalba.com/adaf';
u = s.match(/(?!^)http:\/\/.+?$/)[0];
//=> http://blabalba.com/adaf

Related

Finding difference between two strings and storing the difference one in other string in javascript [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 1 year ago.
Improve this question
I need to find difference between two strings.
string newemails = peter#xyz.com,john#xyz.com,harry#xyz.com,prince#xyz.com;
string oldemails = peter#xyz.com,john#xyz.com,johnson#xyz.com,harry#xyz.com,prince#xyz.com;
The expected output is johnson#xyz.com and log it to the new string.
Is there any way to do this in JavaScript?
You can split the strings by comma, then filter out the newemails from the oldemails:
var newemails = 'peter#xyz.com,john#xyz.com,harry#xyz.com,prince#xyz.com';
var oldemails = 'peter#xyz.com,john#xyz.com,johnson#xyz.com,harry#xyz.com,prince#xyz.com';
var newemailsArr = newemails.split(',');
var diff = oldemails.split(',').filter(m => !newemailsArr.includes(m)).join(',');
console.log(diff);

Convert JavaScript string format into another [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 1 year ago.
Improve this question
I have a mobile no like (408) 931-4377 and need to create a format like (000) 000-0000 for validating other mobile nos
Please suggest how this can be achieved?
Use String.replace in javascript
Reference
const number = "(408) 931-4377";
console.log(number.replace(/[0-9]/g, "0"));
Use Regular Expressions for this Validation.
const number = "(408) 931-4377";
const mobilecheck = RegEx(/^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$/);
if(mobilecheck.test(number)){
// do something
}
else{
// do something
}```

Cut a string into two parts before any digit in js? [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 4 years ago.
Improve this question
What I have:
add-category
add-exam
a-category1
a-category2
...
a-category[n]
What I need:
I need to cut string on two parts as 'a-category' and '1' or just 'add-exam' if no digit in row.
let str = 'a-category2';
let splitStr = str.split(/(\d+)/);
console.log('string--->' + splitStr[0]);
console.log('digit---->' + splitStr[1]);

Email Regex for Javascript Which not start with Number [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 4 years ago.
Improve this question
^[a-zA-Z]\w+#[a-zA-Z_]+?\.[a-zA-Z]{2,4}$
i had tried this regex for email but it allow following cases
123#mail.com
example.mail#mail.com
Here is the code which searches for the number at the start.
If number is matched it prints message in console.
let regex = /^[0-9]/;
let object = [{email:'123#mail.com'},{email:'example.mail#mail.com'}];
for(let i =0;i<object.length;i++){
if(object[i].email.match(regex)){
console.log('E-mail ',object[i].email,' is not valid.')
}
}
This is the used regex: ^[0-9]

Search for a given row in a table [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
What is the difference between regular expression Modifier 'i' and 'm'.
Example:
var str = "Visit W3Schools";
var patt1 = /w3schools/i;
document.write(str.match(patt1));
var str = "Visit W3Schools";
var patt1 = /w3schools/m;
document.write(str.match(patt1));
Um, it's kinda hard to see what you're asking, but I think what you want is
new RegExp('1.*'+str,'i');
The period (.) matches any character and the * matches any character zero or more times. I'm not 100% on the syntax of that regex in javascript, but that should be a minor issue. Maybe a str.toString() is missing or something?

Categories

Resources