Regular expression to get value [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was wondering how I would go about getting the value from this string:
LUGG::1::LUGG::5-GBP
In this case, the value retrieved would be "1".

It's hard to say for certain without knowing all the possible options of input strings, but for example if you always just want to get the number that has :: on its left AND :: on its right (1 in your example):
var myInput = 'LUGG::1::LUGG::5-GBP';
var myNumber = myInput.match(/::(\d+)::/)[1];
alert(myNumber); // alerts 1

Related

javascript match: How to get some specific words? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
my problem is that i can not get numbers and "-" from all "[]"!
here is my input text:
sasa[1-10][2][1-12]
and here is my javascript:
m = input.val().toString().match(/(\[[0-9-]+\])/);
Try
m = input.val().toString().match(/(\[[0-9-]+\])/g);
added global flag to match all matching values ^

Replace string with Javascript only under certain condition [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I need to do a find and replace of a certain string when this particular page loads, but only if it has a specific value associated with it. Example:
The following strings may all load on the page:
"0: Here is the string"
"1: Here is the string"
"2: Here is the string"
I only want the string to be replaced if the value is 0, the 1 and 2 values should not have the string replaced even those it's the same text as the 0 value. I imagine this would need to be a combination of an if else statement and a replace statement, but I am not sure how the syntax would work.
One way to do it is:
if(s.indexOf('0:') == 0)
s = s.replace('Here is the string','the new string');

How to remove unwanted characters from a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Guys i need to remove 138;# and #140;# from a string. I need a function that will work regardless of the number prepending the ;#
The original string is :-
138;#RM Bridge;#140;#Maconomy
Basically i want "RM Bridge, Maconomy" so i can split into an array.
string = string.replace(/([0-9]+)?;#/g, '');
But keep in mind that you'll get RM BridgeMaconomy instead of RM Bridge, Maconomy, because there is no , in your string.

How to sort a string (in ascending order ) which has numbers seperated with comma in javascript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is my code in my javascript:
var concatId = document.MyForm.concatIdSaved.value;
This is giving me string as 3,2,4,00201,
After 00201 iam getting comma also.
All four values are coming in a single String.
Now i want this string as 00201,2,3,4
Someone please help me on this.
var concatId = document.MyForm.concatIdSaved.value.split(",").sort().join();

Phone number regex in javascript/jquery on (000)000-0000 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm using jquery.validate.addMethod(), and need a regex for specific phone number format. I somehow knew it before, but since I don't use regex that much, I forgot.
So, this is just a simple question: How do you create a regex for javascript on the following format:
(000)000-0000
The current phoneUS format which jQuery Validate possess is not applicable to the current problem.
/^\(\d{3}\)\s?\d{3}-\d{4}$/
This allows for a space after the closing parenthesis as well.
Something like this:
/^\(\d{3}\)\d{3}-\d{4}$/

Categories

Resources