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 5 years ago.
Improve this question
I am trying to convert JavaScript regular expression to java regular expression. here is my current javascript regular expression that I am trying to convert :
var re = /\a(?![^<]*>)/g;
I have searched and found out that I need to change the back-slash / into double back-slashes // and start with "
but what about /g at the end? do we need to change it too?
Thank you
The equivalent regex is:
string regex = "\\a(?![^<]*>)";
There is no equivalent of the g flag in JAVA, you have to use replaceall() instead of replace() if you want to replace or use a matcher and a while loop (see How can I find all matches to a regular expression in android).
Related
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 have a simple Regex to match 'der' - /der/g
I need the context around the match. Is there any way to build the regex that way? Thank you in advance.
If you want to match the context plus the search string, simply add the optional range before and after the searched string: .{0,5}der.{0,5}
If you want to get the context only, you have to fetch it separately: (.{0,5})der(.{0,5})
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'm somewhat new to regex. I understand most of the basics but what I'm trying to do is beyond my knowledge, and may not even be possible.
I'm trying to make a regex in JavaScript that can match a series of function calls in the following pattern.
Name.Name(Params).Name(Params)
The names could be any standard java function name. I understand how do to this part. The params though can be different number of parameters (Currently only 0-2)
My biggest issue however is that params could potentially take ANY string with either a single or double quotation mark, or variable names. I have added some examples below as I need all of these to work with my regular expression (if Possible).
Examples:
Func.Foo().Bar()
Foo.Bar('foo', bar).Foobar()
Foo.Bar("foo", "bar").bar(')')
Foo.Bar('/"foo/"').bar("foo(bar/")")
My main concern here is I cant just look for a opening and parentheses or even 2 quotation marks.
Is it possible to use a regex so that I can parse the function call and parameters out?
The short answer to the Question in the title is yes, you can build a regex that matches any substring. But unfortunately that is not what you want. If you allow arbitrary substrings your regex will either match many cases you dont want to match or it will become extremely complex (see the email regex for an example).
What you want is a tokenizer!(https://medium.freecodecamp.org/how-to-build-a-math-expression-tokenizer-using-javascript-3638d4e5fbe9)
Edit: for the solutions in the comments: the ast parser is for java, the author wants to use javascript.
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 5 years ago.
Improve this question
I am looking for a JavaScript regular expression that would match the word "foo" in a phrase "This <is foo" or "This is foo" or "This is foo>" but would not match in the phrase "This <is foo>". I know that in other languages this is solved by using negative lookbehinds, but AFAIK, JavaScript does not support these. I have come across similar questions, but none of them matched exactly what I am looking for, and I can't think of a solution on my own. I would be grateful for any hint.
I am testing my attempts here.
You can match it as group not bounded by the opening and closing brackets.
[^<].*(foo).*[^>]
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 have a mac address: "22:33:44:12:34:56" and I want to prune out all the semicolons.
If I do it without regular expressions it would be :
"22:33:44:12:34:56".replace(":","")
then "2233:44:12:34:56".replace(":","") until I finish with all colons.
What is the regular expression that does this in a single batch?
Regex flag g makes the global search:
"2233:44:12:34:56".replace(/:/g, "");
REF: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp
Do this :
"22:33:44:12:34:56".replace(/:/g,"")
The MDN explains how you can use replace with a regex, and especially the g flag which makes the function replace all occurrences and not just the first one.
How about this?
'22:33:44:12:34:56'.split(':').join('')
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
Are they useful to know? How are they used?
Regular expressions are not a JavaScript-specific feature and are typically used to check for faults in use input, for example to notify users who forget the # or domain part of an email address or too few/many digits in a phone number. For more examples, look over there.
Email address validation
JavaScript is like Perl, has native regular expression notation.
Regular expressions are used to match texts. For example, validating age:
if (field.value.match(/^\s*\d+\s*$/) === null) alert("error: invalid age.");
Read this for a documentation: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp
and JS form validation tutorial:
http://www.devarticles.com/c/a/JavaScript/Form-Validation-with-JavaScript-Regular-Expressions-Part-1/