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 2 years ago.
Improve this question
How can i find a string between two strings with regex for example i want find example.com in string https://example.com/path OR http://example.com/path
var str = "https://example.com/path";
str.match(/(?!http:\/\/|https:\/\/)(.*)(?!\/)/g);
Why not use URL
const url = new URL("https://example.com/path");
console.log(url.hostname)
you want to know if the string contains it ?
console.log(!!('https://example.com/path'.match(/example\.com/)))
Also, check this :
https://www.w3schools.com/jsref/jsref_includes.asp
might be useful for you
Related
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 last month.
Improve this question
How do i match the url below ?
I want my regex to return true if my url pattern is
/products/e2e-test-products-2022-08-17T18-30-49-882Z:7ebee29f-dde2-4446-b2b1-327c15fbbabb/items
and return false when the url is
/products/e2e-test-products-2022-08-17T18-30-49-882Z:7ebee29f-dde2-4446-b2b1-327c15fbbabb/cart/items
const myRegex = /^\/products\/[^/]*\/items$/;
myRegex.test('/products/e2e-test-products-2022-08-17T18-30-49-882Z:7ebee29f-dde2-4446-b2b1-327c15fbbabb/items')
true
myRegex.test('/products/e2e-test-products-2022-08-17T18-30-49-882Z:7ebee29f-dde2-4446-b2b1-327c15fbbabb/cart/items')
false
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 3 months ago.
Improve this question
I have a string with HTML in between. What I want to achieve is add a space in between after every 2nd character.
For example for input like below -
'<span>234567</span><span>34526754</span>'
'<span>23 45 67</span><span>34 52 67 54</span>'
How can I achieve this in JavaScript?
let str = '<span>234567</span><span>34526754</span>'
str.match(/(?<=\<span>).*?(?=<\/span>)/g).forEach(s=>{
str = str.replace(s, s.match(/.{2}/g).join(' '))
})
console.log(str)
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 a good and best RegExp for validate Iranian phone number like this:
0903*******
0918*******
in this RegExp should check the user should just start phone number with 0 not other things like area code (+98)
try it:
("^[0][9][0-9][0-9]{8,8}$")
Using case in js:
const IsValidPhone = (val) => {
let regex = new RegExp("^[0][9][0-9][0-9]{8,8}$").test(val);
return regex;
};
You can use this regex:
/^(09)[0-9]{9,9}$/gu
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 3 years ago.
Improve this question
I don't no how regex works. but I have a url like:
http://localhost/BetaLeren/public/dashboard/general/video.php?video=13&time=19
but I want it that way:
http://localhost/BetaLeren/public/dashboard/general/video.php?video=13
How I can i do that with refex?
or is there a better way?
If you'll always have video= followed by time=, you could use the following regex:
const link = 'http://localhost/BetaLeren/public/dashboard/general/video.php?video=13&time=19';
const updatedLink = link.match(/^.+video=\d+/)[0];
console.log(updatedLink);
^ represents the beginning of the string.
.+ represents any character 1 or more times.
\d+ represents any digit 1 or more times.
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
Does anyone know how can I get the last digits 192.168.1.180
Example : 192.168.1.180 from this ip address i want to extract 180.
Thanks in advance
Well, if that ip address is a string you could always use the split function.
let str = "192.168.1.180";
let x = str.split(".")[3];
// where str is the ip and x is the last part you want to extract
console.log(x)
Use:
let ip = '192.168.1.180';
let last = ip.split('.')[3];
console.log(last); // '180'