Regular Expression / String matching other than equality check with groovy.
I want to have a string comparison operation using a groovy expression.
Not an equality check, but something like
#{variableName like 'IC%'?'true':'false'}
I saw some operators like
#{bindings.gradeName.inputValue =~ 'IC'?true:false}
But it doesnt seem to be working.
Is it possible with groovy?
Arun
Hi
nything will do.
And not using bean.
This expression has to added in an AMX page (ADF Mobile
It depends on where you want to execute this. Groovy in a validation script would be different to EL in a page as they would be in different stages in the lifecycle.
Now for ADF MObile this may be different, I dont know.'
If its to be part of a validation then you can call the source methods in groovy and do the comparison.
from a validator for instance:
source.getGradeName() returns the grade name before commiting.
String enteredgrade = source.getGradeName();
if (enteredgrade.index(0).equals('I') and enteredgrade(1).equals('C'){
do what you want here. i.e. return true or false etc.
el in a page would look entirly different but you can implement this same functionality in a bean, access it via the accessors and then return true or false.
if you are already using EL and you managed to link your page with JSTL, you will have to define the access variable in the header section inorder to access it and then use "startswith", though I havent tried it this way.
Similar Messages
-
Regular Expressions / String Match
Hi Everyone,
thankx for reading this
I'm programing a oracle form which at one part read's the full path into a file (a text file) and place's it on a VARCHAR2 field. This is the path into the file and not the file data.
I would like to match this string (the file path) to a another one (in order to know if the file name respect some rules). This is a very easy thing to do under Perl / PHP and other languages. But how can i do this under PL/SQL ?
I have search but failed to find any clue.
Any pointers would be great, or a small example
Thankx Stay Happy
Miguel AngeloHi,
you can use INSTR and SUBSTR for String comparison
INSTR(char1,char2) shows you the first occurence of char2 in char1
INSTR(char1,char2,n,m)
shows the m'th occurence of char2 in char1 starting on n
Frank -
"Match Regular Expression" and "Match Pattern" vi's behave differently
Hi,
I have a simple string matching need and by experimenting found that the "Match Regular Expression" and "Match Pattern" vi's behave somewhat differently. I'd assume that the regular expression inputs on both would behave the same. A difference I've discovered is that the "|" character (the "vertical bar" character, commonly used as an "or" operator) is recognized as such in the Match Regular Expression vi, but not in the Match Pattern vi (where it is taken literally). Furthermore, I cannot find any documentation in Help (on-line or in LabVIEW) about the "|" character usage in regular expressions. Is this documented anywhere?
For example, suppose I want to match any of the following 4 words: "The" or "quick" or "brown" or "fox". The regular expression "The|quick|brown|fox" (without the quotes) works for the Match Regular Expression vi but not the Match Pattern vi. Below is a picture of the block diagram and the front panel results:
The Help says that the Match Regular Expression vi performs somewhat slower than the Match Pattern vi, so I started with the latter. But since it doesn't work for me, I'll use the former. But does anyone have any idea of the speed difference? I'd assume it is negligible in such a simple example.
Thanks!
Solved!
Go to Solution.Yep-
You hit a point that's frustrated me a time or two as well (and incidentally, caused some hair-pulling that I can ill afford)
The hint is in the help file:
for Match regular expression "The Match Regular Expression function gives you more options for matching
strings but performs more slowly than the Match Pattern function....Use regular
expressions in this function to refine searches....
Characters to Find
Regular Expression
VOLTS
VOLTS
A plus sign or a minus sign
[+-]
A sequence of one or more digits
[0-9]+
Zero or more spaces
\s* or * (that is, a space followed by an asterisk)
One or more spaces, tabs, new lines, or carriage returns
[\t \r \n \s]+
One or more characters other than digits
[^0-9]+
The word Level only if it
appears at the beginning of the string
^Level
The word Volts only if it
appears at the end of the string
Volts$
The longest string within parentheses
The first string within parentheses but not containing any
parentheses within it
\([^()]*\)
A left bracket
A right bracket
cat, cag, cot, cog, dat, dag, dot, and dag
[cd][ao][tg]
cat or dog
cat|dog
dog, cat
dog, cat cat dog,cat
cat cat dog, and so on
((cat )*dog)
One or more of the letter a
followed by a space and the same number of the letter a, that is, a a, aa aa, aaa aaa, and so
on
(a+) \1
For Match Pattern "This function is similar to the Search and Replace
Pattern VI. The Match Pattern function gives you fewer options for matching
strings but performs more quickly than the Match Regular Expression
function. For example, the Match Pattern function does not support the
parenthesis or vertical bar (|) characters.
Characters to Find
Regular Expression
VOLTS
VOLTS
All uppercase and lowercase versions of volts, that is, VOLTS, Volts, volts, and so on
[Vv][Oo][Ll][Tt][Ss]
A space, a plus sign, or a minus sign
[+-]
A sequence of one or more digits
[0-9]+
Zero or more spaces
\s* or * (that is, a space followed by an asterisk)
One or more spaces, tabs, new lines, or carriage returns
[\t \r \n \s]+
One or more characters other than digits
[~0-9]+
The word Level only if it begins
at the offset position in the string
^Level
The word Volts only if it
appears at the end of the string
Volts$
The longest string within parentheses
The longest string within parentheses but not containing any
parentheses within it
([~()]*)
A left bracket
A right bracket
cat, dog, cot, dot, cog, and so on.
[cd][ao][tg]
Frustrating- but still managable.
Jeff -
Regular expression to replace "emtpy space" ( ) bitween words with +
Hallo!
When I wish to find in code something like this:
12144541 FirstWord SecondWord
regular expression for that is:
(\d{1,100})[\s-]\D{1,100}[\s-]\D{1,100}
Now, please help me tu find regular expression to replace
"emtpy space" ( ) bitween words with +
12144541 FirstWord SecondWord to become
12144541+FirstWord+SecondWord
Thank you very, very, very much!A simple-minded solution is to use \s to match all
whitespace; e.g. find \s and replace with +. DW CS3, at least, is
smart enough to not replace end of line characters with the '+'
character if you limit your search & replace to text. -
Are there more DVD menu other than what comes with Premiere Elements 13
are there more DVD menu other than what comes with Premiere Elements 13, anyone Please
how many systems
I just answered this question in a duplicate that you posted.
how many systems can I download my adobe premiere 13 on,
Duplicated posts tend to be confusing for the person originating the question as well as those trying to reply.
Typically a moderator closes or deletes one of the duplicates when it is seen.
So, please continue the discussion on this topic in your other thread whose link is shown above.
Thank you.
ATR -
Regular Expression for Match Pattern (string) Function
I need to find a variable length string enclosed by brackets and
within a string. Can't seem to get the regular expression right for
the Match Pattern function. I'm able to get the job done using the
Token function, but it's not as slick or tight as I'd like. Does
anybody out there have the expression for this?Jean-Pierre Drolet wrote in message news:<[email protected]>...
> The regular expression is "\[[~\]]*\]" which means:
> look for a bracket "\[" (\ is the escape char)
> followed by a string not containing a closing bracket "[~\]]*"
> followed by a closing bracket "\]". The match string include the
> brackets
>
> You can also read "Scan from String" with the following format:
> "%[^\[]\[%[^\[\]]" and read the 2nd output. The brackets are removed
> from the scanned string.
Thanks, Jean_Pierre
I did some more experimenting after posting and found that \[.*\] also
works with the match pattern function. Thanks for your input.
sm -
Regular expressions string length
Hi
New to regular expressions and trying to create an expressions that will test if a string does not contain any number and is less than 20 characters long! This works for determining if it has any numbers in it, but how do I specify that it can be between 1 and 20 characters in length? The + means >1 but how do I cap it?
Pattern p = Pattern.compile("[a-zA-Z]+");
Matcher m = p.matcher(value);
if (m.matches()) System.out.println("yes");I have tried [a-zA-Z]+{5} but that doesn't work. Any handy hints... can't find much stuff that is applicable via google, frustrating.
Thanks.Looce wrote:
Pattern p = Pattern.compile("[a-zA-Z]{1,20}"); // repetition totally replaces +, doesn't coexist with it
Matcher m = p.matcher(value);
if (m.matches()) System.out.println("yes");
Note that the following code can be shortened by doing:
if(value.matches("[a-zA-Z]{1,20}")) { /* ... */ } -
Regular expression to match incremental or consecutive digits
I need to process a string containing all digits to ensure that it does not contain either
(a) a group of 5 or more consecutive identical digits eg. 11111
(b) a group of 5 or more incremental/decremental digits eg 12345, 98765
Also, is there a processing difference between the reluctant and greedy qualifiers?
Case (a) seems to be easy:
Pattern pattern = Pattern.compile("[0-9]{5,}?");but what about (b) ? From the documentation it seems that using capturing groups might be helpful, but they are confusing me.
Finally how do I merge multiple pattern matching strings into one overall regular expression so I can make one pass on the input to see whether it is valid or not?
Thanks
Chrisgive this code a try
public class Test {
static boolean check(String str) {
loop : for (int x = 0, y; x < str.length() - 4; x += y) {
y = 1;
int dif = (str.charAt(x+y) - str.charAt(x)); //assuming you don't whant 90123
if (dif >= -1 && dif <= 1) {
for (; y < 4; y++) {
if ((str.charAt(x+y+1) - str.charAt(x+y)) != dif) {
continue loop;
return true;
return false;
public static void main(String[] args) {
System.out.println(check(args[0]));
} -
Urgent!!! Problem in regular expression for matching braces
Hi,
For the example below, can I write a regular expression to store getting key, value pairs.
example: ((abc def) (ghi jkl) (a ((b c) (d e))) (mno pqr) (a ((abc def))))
in the above example
abc is key & def is value
ghi is key & jkl is value
a is key & ((b c) (d e)) is value
and so on.
can anybody pls help me in resolving this problem using regular expressions...
Thanks in advance"((key1 value1) (key2 value2) (key3 ((key4 value4)
(key5 value5))) (key6 value6) (key7 ((key8 value8)
(key9 value9))))"
I want to write a regular expression in java to parse
the above string and store the result in hash table
as below
key1 value1
key2 value2
key3 ((key4 value4) (key5 value5))
key4 value4
key5 value5
key6 value6
key7 ((key8 value8) (key9 value9))
key8 value8
key9 value9
please let me know, if it is not possible with
regular expressions the effective way of solving itYes, it is possible with a recursive regular expression.
Unfortunately Java does not provide a recursive regular expression construct.
$_ = "((key1 value1) (key2 value2) (key3 ((key4 value4) (key5 value5))) (key6 value6) (key7 ((key8 value8) (key9 value9))))";
my $paren;
$paren = qr/
[^()]+ # Not parens
|
(??{ $paren }) # Another balanced group (not interpolated yet)
/x;
my $r = qr/^(.*?)\((\w+?) (\w+?|(??{$paren}))\)\s*(.*?)$/;
while ($_) {
match()
# operates on $_
sub match {
my @v;
@v = m/$r/;
if (defined $v[3]) {
$_ = $v[2];
while (/\(/) {
match();
print "\"",$v[1],"\" \"",$v[2],"\"";
$_ = $v[0].$v[3];
else { $_ = ""; }
C:\usr\schodtt\src\java\forum\n00b\regex>perl recurse.pl
"key1" "value1"
"key2" "value2"
"key4" "value4"
"key5" "value5"
"key3" "((key4 value4) (key5 value5))"
"key6" "value6"
"key8" "value8"
"key9" "value9"
"key7" "((key8 value8) (key9 value9))"
C:\usr\schodtt\src\java\forum\n00b\regex> -
How to form a regular expression for matching the xml tag?
hi i wanted to find the and match the xml tag for that i required to write the regex.
for exmple i have a string[] str={"<data>abc</data>"};
i want this string has to be splitted like this <data>, abc and </data>. so that i can read the splitted string value.
the above is for a small excercise but the tagname and value can be of combination of chars/digits/spl symbols like wise.
so please help me to write the regular expression for the above requirementyour suggestion is most appreciable if u can give the startup like how to do this. which parser is to be used and stuff like that
-
Regular Expression for match pattern
Hi guys, I need some help.
In one part of my test system, I give to the program a sequence of temperatures, which are numbers separated by a comma. Due to a possible error, the user can forget the coma, and the program gets unexpected values.
For example, "20, 70, -10" is a right value, whereas "20 70, -10" would be a wrong one.
Which regular expression will detect this comma absence?
Thanx in advance.OK, makes it more difficult (and more fun )
My original version failed also when the space was forgotten. DOH!
Try this version. It get's complicated cause the scan from string likes ignoring spaces... So we change the spaces
Hope this helps
Shane.
PS The ideas given by others are still a better solution, but if you're stuck........
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Attachments:
Check input string with commas(array).vi 39 KB -
Regular expressions for matching file path
Could someone give me idea that how can i compare a fixed path, with the paths user gives using regular expressions?
My fixed path is : src\com\sample\demo\work\gui\.**
and user may give like src\com\sample\demo\work\gui\test.jsp, src\com\sample\demo\work\gui\init.jsp etc.
Any ideas are appreciated and thanks in advance....and if you insist on using regexes, you'll have to double-escape the backslashes: if ( userString.matches("src\\\\com\\\\sample\\\\demo\\\\work\\\\gui\\\\.*") ) { Whether you use regexes or not, you'll save yourself a lot of hassle by converting all backslashes to forward slashes before you do anything with the strings: userString = userString.replace('\\', '/');
if ( userString.matches("src/com/sample/demo/work/gui/.*") ) {
// or...
if ( userString.startsWith("src/com/sample/demo/work/gui/") ) { -
Command line style regular expression string parser
Hi people,
I am currently working on a program where I need to parse a file (or any input stream) line by line. I then need to parse every line for arguments. Each line is formatted similar to how arguments are passed to the command line. The regular expression needs to split every line by any encountered whitespace, but needs to be able to retain any whitespace within double quotes (i.e. "some spaced text here"). Arguments can be numbers, booleans and (quoted) strings. Quoted strings must also be able to have escaped quotes in it (as below). The quotes for the quoted string (the outer ones, obviously not the escaped ones) do not necessarily have to be retained.
An example input line:
arg1 arg2 "arg 3" "arg 4" 987 arg6 "arg \"arg \"arg 7"
Desired example output:
arg1
arg2
arg 3
arg 4
987
arg6
arg "arg "arg 7
After the input line has been split up the program will handle any parsing (i.e. numbers, booleans, etc.). The program currently uses a simple for loop to iterate over all characters in the line and splits it up appropriately by checking every character. However, if this can be done automatically by using a regular expression passed to String.split() (or with some use of the regex package), it would remove quite a bit of redunant code and make the program that much more maintainable.
I do not have much experience with regular expressions since I have never really had the need to use them, but if they can work in this case it would be great.
Thanks in advance for any help.Almost any parsing problem can be solved if you throw a big enough and ugly enough regex at it, or so I'm told.
I think what you are doing is also amenable to java.io.StreamTokenizer:
import java.io.*;
import static java.io.StreamTokenizer.*;
public class StreamTokenizerExample {
public static void main(String[] args) throws IOException {
StringReader input = new StringReader("arg1 arg2 \"arg 3\" \"arg 4\" 987 arg6 \"arg \\\"arg\\\" arg 7\"\nnextline");
StreamTokenizer in = new StreamTokenizer(input);
in.eolIsSignificant(true);
for(int ttype; (ttype = in.nextToken()) != TT_EOF; ) {
switch (ttype) {
case TT_WORD:
System.out.println("String[" + in.sval + "]");
break;
case TT_NUMBER:
System.out.println("number[" + in.nval + "]");
break;
case TT_EOL:
System.out.println("[EOL]");
break;
case '"':
System.out.println("quoted[" + in.sval + "]");
break;
default:
System.out.println("unexpected " + ttype);
{code} -
How can I use regular expression to match this rule
I have a String ,value is "<a>1</a><a>2</a><a>3</a>",and want to match other String like "<a>1</a><a>8</a>",if the one of the first string(like "<a>1</a>") will occur in the second string,then will return true.but I don't know how to write the regular expresstion.
ThxFine fine. :P
I was a little bored, so here's some code that uses Strings and a StringBuffer (though you could use a String in place of the StringBuffer). Is this perhaps better? :)
String testMain = "<a>1</a><ab>2</ab><ab>3</ab>";
String test = "<ab>1</ab><ab>3</ab>";
String open = "<ab>";
String close = "</ab>";
StringBuffer search = new StringBuffer();
String checkString = null;
int lastCheck = 0;
int start = 0;
int finish = 0;
boolean done = false;
while (!done) {
start = test.indexOf(open);
finish = test.indexOf(close);
if ((start == -1) || (finish == -1)) {
System.out.println("No more tags to search for.");
done = true;
else {
checkString = test.substring((start + open.length()), finish);
search = new StringBuffer();
search.append(open);
search.append(checkString);
search.append(close);
if (testMain.indexOf(search.toString()) != -1) {
System.out.println("Found value: " + checkString);
test = test.substring(finish + close.length());
Resulting output:
Found value: 3
No more tags to search for.
-G -
Hi,
I'm looking for a single regular expression.
E.g. My string is 'get data for comparison'. So when using regular expression as \Wcompar then it returns true.
But I dont want it to return true for string 'get data for comparable' with the same regular epression.
Here, I do not want string comparable and rest all the forms of compar to be selected.It's not really clear what you need, perhaps something like this?
-- data:
with t as
select 'get data for comparison' txt from dual union all
select 'get date for compar xxxxx' txt from dual union all
select 'compar xx' txt from dual union all
select 'compare xx' txt from dual union all
select 'xx compar' txt from dual union all
select 'xx compare' txt from dual
-- query:
select txt from t
where regexp_like(txt,'(\W|^)compar(\W|$)');
TXT
get date for compar xxxxx
compar xx
xx compar(\W|^) means word-limit or start of the string
(\W|$) means word-limit or end of the string
Edited by: hm on 21.12.2011 05:29
Maybe you are looking for
-
Use of ODP and casual application freeze-up
Hello, I'm writing a small application which connects to MS SQL 2000 and Oracle 10.2.0.1.0 and transports data between them. When it comes to biggest table which is called CLANKY, there is 11892 records with clob columns and fulltext index over it. B
-
XI: new termonologies in Integration Repository "operation" "action"
Hi Friends, Can anyone tell me how new concepts within integration repository like "actions" "operation" are mapped to old way of "message interface" etc. Thanks in advance, Regards, Ujwal
-
How to remove trailing spaces in SQL PLUS spool
Hi, I've requirement to pull data from tables and I'm using sqlplus spool to automate data fetch from various tables: I'm using the following script for the same : set echo off set feedback off set pagesize 0 set linesize 2000 set heading on set trim
-
Ive just had a new iphone but its on a different network how do i change it
ive just ordered a new phone on insurance and it has come on o2 and i am on orange how would i be able to change it so it lets my knew phone work?
-
[solved] kdemod 4.2.4 and kernel 2.6.30 lost effects
Hello, I wonder is anybody encountered similar problem (see topic)? my system today installed official arch kernel 2.6.30-ARCH so my updated system looks as follows: system: Arch linux i686 up to date (system update 06-23-09) kdemod 4.2.4 (up to date