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
I have this code:
$(this).text().replace(/write\s(\w+);/g, "$1");
and this text:
write testing code;
but show only "testing"!
How to take all words and show "testing code"?
thx
console.log($("#my_element").text().replace("write",""));
You don't need a regex if replacing the string "write" is all you want to do.
To change the element's inner html:
$("#my_element").html(($("#my_element").text().replace("write",""));
If I understand the question correctly you want to strip out the word write from the string and keeping the other words? If this is the case, you can do it like this:
$(this).text().replace(/(\s?)write(\s?)/g, '');
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 2 years ago.
Improve this question
I am trying to construct a regular expression in Javascript such that the string contains more b's than a's. Can contain other characters anywhere but b's have to be more than a's. Could anybody help?
Simplest route:
let moreAsThanBs = (str) => str.match(/a/ig).length > str.match(/b/ig).length;
console.log(moreAsThanBs("Are there more As than Bs in this sentence?"));
console.log(moreAsThanBs("Are there more As than BBBBBs in this sentence?"));
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 4 years ago.
Improve this question
I want to write a regex for matching *#xxx[.]gr in js.
My regex so far :
/^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
I want : *#xxx.gr
If I understand your specs correctly this should suit you:
/^[^<>()\[\]\\.,;:\s#"]+#[^<>()\[\]\\.,;:\s#"]{3}\[\.\][^<>()\[\]\\.,;:\s#"]{2}$/g
Demo: https://regex101.com/r/kfjAG9/2
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 5 years ago.
Improve this question
I tried this : [fl]ady?[ing] ?[rb]ug!?
I know [fl]ad[y]?(ing)? ?[br]ug!? is an answer
Can this be solved using character sets only? Must match both.
ladybug
fading rug!
I believe this should work for you
[fl]ad(y|ing)\s?[br]ug?
Check out http://www.regexpal.com/
Using character sets only? So, it doesn't matter what other letter combinations it matches as well? Mmm. Then
[fl]ad[giny]+[\sbrug!]+
would do. See: https://regex101.com/r/FJWJyM/1
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
The following code works, but I wonder if there is a better way to achieve the same result:
var regex = /define\((\s+)?['|"](PRIVATE_KEY)['|"],(\s+)?['|"](.*)['|"](\s+)?\)/i;
Test:
regex.test("define('PRIVATE_KEY', 'MYSECRETKEY');");
https://regex101.com/r/pW0qS0/4
First I think you don't need to use pip within character class (if you want to match only one quote and double quote) also instead of (\s+)? you can use \s*:
/define\(\s*['"](PRIVATE_KEY)['"],\s*['"](.*)['"]\s*\)/i
See demo https://regex101.com/r/dL1vF4/3
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 8 years ago.
Improve this question
I'm trying to write regexp to find a string who start and ends with the same number like so :
2aldkc2 <----
4alou4 <----
edit , i forget to motion what i have tried so far :
^(\d).^([^h].*$)
but this doesn't work
Use capturing group.
^(\d).*\1$
The regex captures the first digit and match that particular line only if the last character is also the same as the one captured.
DEMO