I am working with smartgwt since three months.
I have encountered a problem with the specific method of the string class.
It seems that the matches never works, even with the simplest one:
String regex = "CEDD";
String input = "CEDD";
input.matches(regex);
this will always returns false. Such piece of code is within a class extending the smartgwt Layout class, and therefore got converted to js and used in front end.
The same fragment obviously works when used in a simple java main standalone class.
Could you point out what to investigate to solve this problem ?
thanks
It looks like GWT doesn't support normal Java regular expressions (i.e. doesn't support Pattern, Matcher and classes/methods that use it.
There is a RegExp class that provides those features, however.
Related
I am using an Engineering Program which lets me Code formulas in order to filter out specific lines in a database. I am trying to look for a certain line in the database which contains e.g. "concrete" as a property.
In the Code I can use regular expressions.
The regex I was using so far looked like this:
".*(concrete).*";
so if the line in the database contains concrete, I will get the wanted result.
Now the Problem is: i would like to switch the word concrete with a variable, so that it Looks like this:
".*(#VARIABLE1).*";
(the Syntax with the # works in the program btw.)
the Problem is: if i set the variable as concrete, the program automatically switches it for 'concrete' . Obviously, the word concrete cant be found anymore, since the searchterm now contains the two ' Symbols in the beginning and i the end.
Is there a way to ignore those two characters using the Right regex?
what I want it to do is the following:
If a line in the database contains "25cm concrete in Grey"
I should get a match from the regex.
with the searchterm ".*(concrete).*"; it works, with the variable ".*(#VARIABLE1).*"; it doesnt.
EDIT:
the whole "Formula" in the program Looks like that:
if(Match(QTO(Typ:="Attribut{FloorsLayer_02_MaterialName}");".*(#V_QUALITY).*" ;"regex") ;QTO(Typ:="Attribut{Fläche}");0)
I want the if-condition to be true, when the match inside is true.
the whole QTO function is just the programs Syntax to use a certain Attribute into the match-function, the middle part is my Problem. I really don't know the programming language or anything,I'm new to this. hope it helps!
Thats more of a hack than a real solution and i'm not sure if it even works:
if you use the regex
.*(#VARIABLE1)?).*
and the string ?concrete(
this will result in a regex looking like this:
.*('?concrete(')?).*
which makes the additional characters optional.
This uses the following assumtption:
the string (#VARIABLE1) gets replaced by the ('<content of VARIABLE1>')
I am trying to get an array of functions, and an array of variables in any mathematical formula in vanilla JS :
A sample :
1+3*9/cos(4+2*x/6+pol)+
BDLIRE(longueur2)+2*8+sin(2)
+g()
For getting functions I use : /([a-zA-Z]+)(?=[(])/gm
https://regex101.com/r/fT3iM7/1
For getting vars I tried : /([a-zA-Z]+[a-zA-Z0-9]?)(?!\()/gm
https://regex101.com/r/mG2fQ2/1
But as you can see it ignores last char of a match followed by a ( char
So i'm a bit stuck with my regex to match variables.
Thanks for any help :)
You cannot use RegEx to parse arithmetic expressions, maybe you can, but you will have a flaky implementation and writing it WILL make you go bonkers.
You need to look into parsers. Check out PEG.js, it is an easy to use framework for writing parsers that compiles into JS, so it IS "vanilla" (Whatever you mean by that...):
http://pegjs.org/
I am trying to avoid using a regexp function when I need to match strings regardless to their accent or case. For instance, when I search for "VOILA", I want to match "voilà".
I noted that it is possible to create a custom collation to achieve that but I don't know where to start and what to expect in terms of performance:
I assume it will be faster than my REGEXP function defined in my VB.net code (see code below). Is that correct? EDIT: this approach doesn't work. I guess the regex is false. Since I am looking for another solution, I'll wait for answers instead of fixing it.
_
Class MyRegEx
Inherits SQLiteFunction
Public Overrides Function Invoke(args As Object()) As Object
Return System.Text.RegularExpressions.Regex.IsMatch(Convert.ToString(args(1)), Convert.ToString(args(0)))
End Function
End Class
The regex build:
Dim testString As String = word.Replace("A", "[=a=]")
testString = testString.Replace("E", "[=e=]")
testString = testString.Replace("I", "[=i=]")
testString = testString.Replace("O", "[=o=]")
testString = testString.Replace("U", "[=u=]")
testString = testString.Replace("Œ", "œ")
testString = "(?i)(\W|^)" & testString & "(\W|$)"
I have read the SQLite documentation on the creation of a custom collation but I don't really get it. Should I define this in my .net application? Can I embed my custom collation in the database to avoid to create it each time?
I guess that it's a common issue considering the number of related questions. However, I haven't seen a single written example achieving this kind of accent/case insensitive search. Can someone share this?
The best lead I have so far would be to create a custom column without accents as described here. This approach seems to be satisfying, but I wanted to get the elegant solution (i.e. custom collate) instead, if it is possible in my case.
Thanks!
So I'm completely new to the overwhelming world of Regex. Basically, I'm using the Gedit API to create a new custom language specification (derived from C#) for syntax-highlighting (for DM from Byond). In escaped characters in DM, you have to use [variable] as an escaping syntax, which is simple enough. However, it could also be nested, such as [array/list[index]] for instance. (It could be nested infinitely.) I've looked through the other questions, and when they ask about nested brackets they only mean exclusively nested, whereas in this case it could be either/or.
Several attempts I've tried:
\[.*\] produces the result "Test [Test[Test] Test]Test[Test] Test"
\[.*?\] produces the result "Test [Test[Test] Test]Test [Test] Test"
\[(?:.*)\] produces the result "Test [Test[Test] Test]Test[Test] Test"
\[(?:(?!\[|\]).)*\] produces the result "Test [Test[Test] Test]Test[Test] Test". This is derived from https://stackoverflow.com/a/9580978/2303154 but like mentioned above, that only matches if there are no brackets inside.
Obviously I've no real idea what I'm doing here in more complex matching, but at least I understand more of the basic operations from other sources.
From #Chaos7Theory:
Upon reading GtkSourceView's Specification Reference, I've figured out that it uses PCRE specifically. I then used that as a lead.
Digging into it and through trial-and-error, I got it to work with:
\[(([^\[\]]*|(?R))*)\]
I hope this helps someone else in the future.
I am attempting to write a MVC model validation that verifies that there is 10 or more words in a string. The string is being populated correctly, so I did not include the HTML. I have done a fair bit of research, and it seems that something along the lines of what I have tries should work, but, for whatever reason, mine always seem to fail. Any ideas as to what I am doing wrong here?
(using System.ComponentModel.DataAnnotations, in a mvc 4 vb.net environment)
Have tried ([\w]+){10,}, ((\\S+)\s?){10,}, [\b]{20,}, [\w+\w?]{10,}, (\b(\w+?)\b){10,}, ([\w]+?\s){10}, ([\w]+?\s){9}[\w], ([\S]+\s){9}[\S], ([a-zA-Z0-9,.'":;$-]+\s+){10,} and several more varaiations on the same basic idea.
<Required(ErrorMessage:="The Description of Operations field is required"), RegularExpression("([\w]+){20,}", ErrorMessage:="ERROZ")>
Public Property DescOfOperations As String = String.Empty
Correct Solution was ([\S]+\s+){9}[\S\s]+
EDIT Moved accepted version to the top, removing unused versions. Unless I am wrong and the whole sequence needs to match, then something like (also accounting for double spaces):
([\S]+\s+){9}[\S\s]+
Or:
([\w]+?\s+){9}[\w]+
Give this a try:
([a-zA-Z0-9,.'":;$-]+\s){10,}