Search for a given row in a table [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
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?

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

Remove everything from string after the second - with a single line in Javascript [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
I want to ensure the language is always extracted from a string, only before the 2nd dash (-)
So
en-AU-Option-A
becomes
en-AU
Is this possible with a single line of Javascript?
Split takes a second argument to specify no. of element desired. so in this case you can specify 2 and it will split upto 2nd - and than join -
let str = `en-AU-Option-A`
console.log(str.split('-',2).join('-'))
Of course it is possible. This is not using regex.
let mystr = 'en-AU-Option-A'
console.log(mystr.split('-').slice(0, 2).join('-'))
Here is a regex solution
var regex = /^([a-z]+|[A-Z]+)\-([a-z]+|[A-Z]+)/g;
var str = 'en-AU-Option-A';
console.log(str.match(regex)) // ["en-AU"]
Try This:
var patt = /[^-]*-[^-]*/ig ;
console.log( patt.exec( 'en-AU-Option-A' )[0] )

Regular express to match `command--o1--o2--o3` [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 7 years ago.
Improve this question
I have a string like command--o1--o2--o3 ( command,o1,o2,o3 are arbitrary words)
And I want get [o1, o2, o3] though a Regular Expression(Not a array operation or other ways. JUST only use Regular Expression).
Is there any idea to accomplish this !?
If you're using JavaScript, and assuming you want all strings after a --, you may do
var things = str.split(/--/).slice(1)
If you just want to get the 2 characters words following --, then you may use
var things = str.match(/--\w\w/g).map(function(s){ return s.slice(2) })

Replace many commas with a space only javascript? [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 8 years ago.
Improve this question
I want to replace commas with a space like this:
If I have 1 comma, like : , I want replace it with a space only.
Or in other cases, I have 2 or more consecutive commas like : ,, or ,,, or ,,,,
I also want to replace the consecutive commas with one space only.
EX: var x = "black,white,,red,,,,blue";
I want to get "black white red blue";
How can I do it.
Thank you very much.
This can be done using JavaScript's replace method using a regular expression:
var x = "black,white,,red,,,,blue";
x = x.replace(/[, ]+/g, " ");
Demo
Try this:
var x = "black,white,,red,,,,blue";
var n = x.replace(/,+/g, ' ');
alert(n);

Regex String URL [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
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

Categories

Resources