Wildcards in string matching?
Right now I have a "fraction converter" class that looks, in part:
case "6":
case "66":
case "67":
case "68":
case "666":
theNumber = "2/3";
break;
Is there any way to use a wildcard or regex in these case statements, so that I can say "6 followed by anything"?
You coud try something like this, just grab the first number
var tmpStr:String = String(myNumber).charAt(0);
switch(tmpStr)
case "6": theNumber = 2/3;
David
Similar Messages
-
I need an execution of commands after the reply from the instrument matches with the string I provided for that i used true or false string match VI on which the true string the matching command and the string is the reply from the instrument. And I put the further executionable commands in frame after frame of sequence loop in the true of the case structure. Amd finally I given all the output strings to the concatenate string to get all the replies as one loop. But when I execute the program the desired result is not available. So kindly please help me to overcome this problem.
Attachments:
basic serial with changes.vi 24 KBYou VI makes absolutely no sense and I would recommend you start with a few simple LabVIEW tutorials before trying to tackle this.
What is the point of the FOR loop with 1 iteration, it might as well not even be there, same difference.
Why is there an abort primitive in the FOR loop, this mean the program will unconditionally stop abort before any downstream code will ever go into action. The program will never get past the FOR loop.
You created a circular data dependency and LabVIEW inserted a feedback node automatically, making things even worse. (see also)
You need to learn about dataflow, execution order, and data dependency.
You need to learn about the various types of tunnels (plain, autoindexing, etc.)
There is a tremendous amount of duplicate code. Large code sections are the same, differeing only by a string. You should only have one copy of that code inside a proper state machine. Have a look at the design templates and examples that ship with LabVIEW.
LabVIEW Champion . Do more with less code and in less time . -
An additional question about regular expressions with String.matches
does the String.matches() method match expressions when some substring of the String matches, or does it have to match the entire String? So, if i have the String "123ABC", and i ask to match "1 or more letters" will it fail because there are non-letters in the String, but then pass if i add "1 or more letters AND 1 or more digits"? so, in the latter every character in the String is accounted for in the search, as opposed to the first. Is that correct, or are there ways to JUST match some substring in the String instead of the whole thing? i WILL make some examples too... but does that make sense?
It has to match the whole String. Use Matcher.find() to match on just a sub-string()
-
String.matches vs Pattern and Matcher object
Hi,
I was trying to match some regex using String.matches but for me it is not working (probably I am not using it the way it should be used).
Here is a simple example:
/* This does not work */
String patternStr = "a";
String inputStr = "abc";
if(inputStr.matches( "a" ))
System.out.println("String matched");
/* This works */
Pattern p = Pattern.compile( "a" );
Matcher m = p.matcher( "abc" );
boolean found = false;
while(m.find())
System.out.println("Matched using Pattern and Matcher");
found = true;
if(!found)
System.out.println("Not matching with Pattern and Matcher");
Am I not matches method of String class properly?
Please throw some lights on this.
Thank you.String.matches looks at the whole string.
bsh % "abc".matches("a");
<false>
bsh % "abc".matches("a.*");
<true> -
String.matches() faulty?
I wondered why my regExp didn't work when I called it with
myString.matches(searchString);So I wrote this test code:
System.out.println("Test: if substring exists:");
String text = "Using org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser as SAX2 Parser";
String search = "as SAX2 Parser";
String regExp = "\\S*("+search.toUpperCase()+"\\S*)";
Pattern pat = Pattern.compile(regExp);
Matcher m = pat.matcher(text.toUpperCase());
while (m.find()) {
System.out.println("found2: "+text.substring(m.start(), m.end()));
System.out.println("Same with String.matches:");
System.out.println("found2: "+text.matches(regExp));and the first custom code matches the regExp and the String.matches() doesn't match. What's the catch?"abc" -> find ("b") -> finds "b"
"abc".matches("b") -> returns false
"b".matches("b") -> returns false
"abc".matches(".b.") > returns trueIf you'd like you could say that matches assumes an
implicit "^" at the beginning and an "$" at the end
of your regex. It tries to match the entire
string and if it doesn't capture it all it returns
false.Why is
"b".matches("b") -> returns false? -
Contains return all the records when the query string matches the columns
I used the multi_column_datastore preference and created an index on three columns (item_name, description,owner_part_number). Now if I do a search:
select * from items where contains(description, 'description') > 0;It returns all the rows in items table, but not all the rows have "description" as a word. I guess Oracle text assumes the query intends to get all the rows as the query string matches one of the column names. My question is whether Oracle Text has any preference settings to alter this behavior?
execute ctx_ddl.create_preference('item_multi_preference', 'MULTI_COLUMN_DATASTORE');
execute ctx_ddl.set_attribute('item_multi_preference', 'columns', 'item_name, description,owner_part_number');
create index item_text_index on items(description) indextype is ctxsys.context filter by owner parameters('LEXER ENG_LEXER WORDLIST ENG_WORDLIST STOPLIST CTXSYS.EMPTY_STOPLIST datastore item_multi_preference MEMORY 1024M');Thanks.
Jun GaoIt looks like a basic_section_group fixes the problem as well, as demonstrated below and I believe a basic_section_group may be more efficient than auto_section_group.
SCOTT@orcl_11gR2> -- recreation of problem:
SCOTT@orcl_11gR2> drop table items
2 /
Table dropped.
SCOTT@orcl_11gR2> create table items (
2 "ITEM_NAME" varchar2(100 byte),
3 "ITEM_NUMBER" varchar2(100 byte),
4 "DESCRIPTION" varchar2(4000 byte),
5 "OWNER" number
6 )
7 /
Table created.
SCOTT@orcl_11gR2> begin
2 FOR Lcntr IN 1..100
3 loop
4 insert into items (item_name, item_number, description, owner)
5 values (dbms_random.string('A', 10),
6 dbms_random.string('A', 10),
7 dbms_random.string('L', 8) || ' '
8 || dbms_random.string('A', 4)
9 || dbms_random.string('A', 5) || ' '
10 || dbms_random.string('A', 10),
11 dbms_random.value(1,10) );
12 end loop;
13 end;
14 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> begin
2 FOR Lcntr IN 1..100
3 loop
4 insert into items (item_name, item_number, description, owner)
5 values (dbms_random.string('A', 10),
6 dbms_random.string('A', 10),
7 dbms_random.string('L', 8) || ' '
8 || dbms_random.string('A', 4) || '111'
9 || dbms_random.string('A', 5) || ' '
10 || dbms_random.string('A', 10), 1234 );
11 end loop;
12 end;
13 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> exec ctx_ddl.drop_preference('ENG_WORDLIST');
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> begin
2 ctx_ddl.create_preference('ENG_WORDLIST', 'BASIC_WORDLIST');
3 ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_INDEX','TRUE');
4 ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_MIN_LENGTH',1);
5 ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_MAX_LENGTH',10);
6 ctx_ddl.set_attribute('ENG_WORDLIST','SUBSTRING_INDEX','TRUE');
7 ctx_ddl.set_attribute('ENG_WORDLIST','WILDCARD_MAXTERMS', 0);
8 end;
9 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> execute ctx_ddl.drop_preference('ENG_LEXER');
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> begin
2 CTX_DDL.CREATE_PREFERENCE ('ENG_LEXER', 'BASIC_LEXER');
3 CTX_DDL.SET_ATTRIBUTE ('ENG_LEXER', 'PRINTJOINS', '@-_');
4 end;
5 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> execute ctx_ddl.drop_preference('items_multi_preference');
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> begin
2 ctx_ddl.create_preference('items_multi_preference', 'MULTI_COLUMN_DATASTORE');
3 ctx_ddl.set_attribute('items_multi_preference', 'columns', 'item_name, description,item_number');
4 end;
5 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> create index items_text_index
2 on items(description)
3 indextype is ctxsys.context
4 parameters
5 ('LEXER ENG_LEXER
6 WORDLIST ENG_WORDLIST
7 STOPLIST CTXSYS.EMPTY_STOPLIST
8 datastore items_multi_preference
9 MEMORY 1024M')
10 /
Index created.
SCOTT@orcl_11gR2> create index owner_idx on items (owner)
2 /
Index created.
SCOTT@orcl_11gR2> exec dbms_stats.gather_table_stats (user, 'ITEMS')
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> select count(*)
2 from items
3 where contains (description, 'description') > 0
4 /
COUNT(*)
200
1 row selected.
SCOTT@orcl_11gR2> -- correction of problem:
SCOTT@orcl_11gR2> exec ctx_ddl.drop_section_group ('items_sec')
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> begin
2 ctx_ddl.create_section_group ('items_sec', 'basic_section_group');
3 ctx_ddl.add_field_section ('items_sec', 'item_name', 'item_name', true);
4 ctx_ddl.add_field_section ('items_sec', 'description', 'description', true);
5 end;
6 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> drop index items_text_index
2 /
Index dropped.
SCOTT@orcl_11gR2> create index items_text_index
2 on items(description)
3 indextype is ctxsys.context
4 parameters
5 ('LEXER ENG_LEXER
6 WORDLIST ENG_WORDLIST
7 STOPLIST CTXSYS.EMPTY_STOPLIST
8 datastore items_multi_preference
9 MEMORY 1024M
10 section group items_sec')
11 /
Index created.
SCOTT@orcl_11gR2> select count(*)
2 from items
3 where contains (description, 'description') > 0
4 /
COUNT(*)
0
1 row selected. -
Email Regular Expression with a String.Match()
I'm currently using a RichTextEditor for a user to build HTML
for a site. However, I want the application to scan for emails and
encode them so they are protected from spam bots when they go to
the live site. I've written a regular expression to find an email
and it seems to work, but it only returns one email at a time from
the string. I have had to revert to a while loop to traverse the
string until I'm satisfied. I don't particularly like that method
and would like to just do one String.match() query to retrieve all
of the emails. Can anyone see something here that I'm missing?Try adding the global flag (g):
var emailPattern:RegExp =
/[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]+/g;
TS -
Cannot get regular expression to return true in String.matches()
Hi,
My String that I'm attempting to match a regular expression against is: value=='ORIG')
My regular expression is: value=='ORIG'\\) The double backslashes are included as a delimiter for ')' which is a regular expression special character
However, when I call the String.matches() method for this regular expression it returns false. Where am I going wrong?
Thanks.The string doesn't contain what you think it contains, or you made a mistake in your implementation.
public class Bar {
public static void main(final String... args) {
final String s = "value=='ORIG')";
System.out.println(s.matches("value=='ORIG'\\)")); // Prints "true"
} -
String.matches() question - regular expression help
How come the following code's if condition returns false?
String someFile="Dr. Phil.pdf";
if (someFile.matches("[.][Pp][Dd][Ff]$")) {
System.out.println("File is a pdf file.");
}When I change the the matches method to matches(".*[Pp][Dd][Ff]$") it works, so does that mean it has to match the entire string to return true? If so, how can I determine if a partial match occured?
If partial matching isn't feasible, then can someone help me look determine if this is the best matching pattern to use:
matches(".*[.][Pp][Dd][Ff]$")Thanks.The documentation is your friend.
[String.matches(regex)|http://java.sun.com/javase/6/docs/api/java/lang/String.html#matches(java.lang.String)] says:
An invocation of this method of the form str.matches(regex) yields exactly the same result as the expression
Pattern.matches(regex, str)And [Pattern.matches(regex, str)|http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#matches(java.lang.String, java.lang.CharSequence)] says
behaves in exactly the same way as the expression
Pattern.compile(regex).matcher(input).matches()And [Matcher.matches()|http://java.sun.com/javase/6/docs/api/java/util/regex/Matcher.html#matches()] says
Attempts to match the entire region against the pattern. -
How can I search for an exact string match in my emails?
I was looking for an old email that I had about Re-Animator The Musical. So, in the search bar in the upper right corner of the Thunderbird window, I typed "re-animator". I got 59 hits, and the message that actually contained the string "re-animator" was 27th, when sorted by relevance. All of the other hits were emails which contained the word "animal" or "animals", which to me has nothing to do with "re-animator". I'm surprised that those were considered hits at all, much less that they were considered more relevant than the one message which actually contained the desired string.
I actually tried three different searches:
reanimator
re-animator
"re-animator"
(i. e. the first two were without quotes and the third was with quotes). All three of these variations had the same problem, though, that messages containing "animal" were ranked before the message containing "re-animator".
The desired message contained the word "Re-Animator" (with that capitalization and hyphenation), and also contained "reanimatorthemusical" as part of a URL that was mentioned in the message. So, I would have expected both the search with the hyphen and the search without the hyphen to have been good hits for this message.
My question is: How can I tell Thunderbird to search for messages that literally contain the string I ask for, and not get "creative" with the matches, as it seems to be doing for some reason?
(I'm using Thunderbird 31.3.0 on Mac OS X 10.9.5.)No, searching for:
"Animator" musical
still has the exact same problem: it still wants to find "animal" instead of "animator". Why?
Yes, I had already read the support article you linked to, but I hadn't found anything in it about why Thunderbird would prefer "animal" over "animator", or how to disable this misfeature. Is there no better documentation for the search bar than that?
(And the search for "Animator The Musical" didn't find my message, simply because my message didn't contain that exact string. It contained "I am on a waiting list for some musical tickets for Sunday, but I haven't heard back yet. It is a preview of The Re-Animator. ( http://www.reanimatorthemusical.com/ )." The search for "Animator The Musical" only had a single hit, your message in which you suggest searching for that.) -
Hi all, I was wondering if it's possible to use wildcards in NSStrings?
So for example say my text is:
"The quick brown fox jumps over the lazy dog".
And I want to extract the string "quick brown fox".
Something like?
(@"quick*fox");
Is there a wildcard that can be used to extract the text between quick and fox? I know I could just strip out 'quick brown fox', but what if I didn't necessarily know it was 'brown' between them, and it was some other word?
Thanks a bunch!There are a couple of regex libraries in the open source.
-
Using wildcards for String compare
Hello,
I want my prog to find out all Strings which start with the letters 'File'. How can I make a String compare by using wildcards ?
Thanx,
FindusYou may use the String method startsWith to find strings beginning with File. eg. filename.startsWith("File")
for more complicated comparisons you might want to use regular expressions. -
Exact String match when calling a recordset
I have a CategoryID column, and a Cats column.
The main catefory for that products is on CategortID, but the in the Cats column is a string of other categories that the item is listed in.
The problem is that if the search is for category id 94, and the Cats column includes 194 the item gets shown.
How so I create a recordset that only returns items that match exactly out of the sting.
I am currently using
WHERE (Categoryid = colname or (INSTR(Cats, colname) >= 1))
Here is an example
Item CategoryID = 139
Cats = 187, 136, 194
But searching for category id displays this item!
Any help appreciatedInstead of INSTR(), try using FIND_IN_SET()
WHERE (Categoryid = colname or (FIND_IN_SET(Cats, colname) >= 1))
FIND_IN_SET() is meant to be for strings, so it might not work. But it does look for a complete match in a comma-separated list. Make sure there is no space between the comma and number when stored. -
Forcing an exact string match in searches
Is there a way of using the Case Exact String and Case Ignore String plugins so I can ensure that the iPlanet directory server only returns exact matches to an LDAP client.
e.g.the difference in
ldapsearch "cn=Abc"
ldapsearch "cn=ABC"
I want to find only "ABC" and NOT Abc or abc or aBc and so on..You can accomplish this using extensible matching rules.
By default, the cn attribute is not case-sensitive. You can search for a case-sensitive cn value with a search filter like:
cn:2.5.3.15:=ABC
This will use the 2.5.3.15 (Case Exact Match) matching rule on the cn attribute. Note that this search will not be indexed, however, and will take longer than a normal cn search for an exact value.
You can find more information on extensible matching in RFC 2254 (http://www.ietf.org/rfc/rfc2254.txt). -
Regular expressions and string matching
Hi everyone,
Here is my problem, I have a partially decrypted piece string which would appear something like.
Partially deycrpted: the?anage??esideshe?e
Plain text: themanagerresideshere
So you can see that there are a few letter missing from the decryped text. What I am trying to do it insert spaces into the string so that I get:
The ?anage? ?esides he?e
I have a method which splits up the string in substrings of varying lengths and then compares the substring with a word from a dictionary (implemented as an arraylist) and then inserts a space.
The problem is that my function does not find the words in the dictionary because my string is only partially decryped.
Eg: ?anage? is not stored in the dictionary, but the word �manager� is.
So my question is, is there a way to build a regular expression which would match the partially decrypted text with a word from a dictionary (ie - ?anage? is recognised and �manager� from the dictionary).I wrote the following method in order to test the matching using . in my regular expression.
public void getWords(int y)
int x = 0;
for(y=y; y < buff.length(); y++){
String strToCompare = buff.substring(x,y); //where buff holds the partially decrypted text
x++;
Pattern p = Pattern.compile(strToCompare);
for(int z = 0; z < dict.size(); z++){
String str = (String) dict.get(z); //where dict hold all the words in the dictionary
Matcher m = p.matcher(str);
if(m.matches()){
System.out.println(str);
System.out.println(strToCompare);
// System.out.println(buff);
If I run the method where my parameter = 12, I am given the following output.
aestheticism
aestheti.is.
demographics
de.o.ra.....
Which suggests that the method is working correctly.
However, after running for a short time, the method cuts and gives me the error:
PatternSyntaxException:
Null(in java.util.regex.Pattern).
Does anyone know why this would occur?
Maybe you are looking for
-
What equipment do i need to set-up a home editing station?
i have been approached by my job to do some editing for them. they are going to pay for me to take a final cut pro class (i graduated from film school in 1998 - right before the big switch was made from flat beds to AVID). Any suggestions of the kind
-
MX 6.1: ARGUMENT values in the wrong place
Im having a very strange problem. I have a CF web service I am invoking and sending it several arguments. In one web service method it works fine and Im only sending 3 arguments. The other I am sending 6 and when I dump the ARGUMENTS arrary the value
-
I've only updated java and adobe flash player. So there is no extensions or anything, just fresh system and fresh browser installed. In error console it says next for example: "Error: Permission denied for <http://media.livepromotools.com> to call me
-
Analyzing Resource Group / Business Unit in a Portfolio
I work at a company that runs large and small projects, some external and some internal. We have many different types of resources that are applied to a given project, with few interchangeable resources (for example, we have six different kinds of en
-
How can I get reimbursed for an accidental charge?
How do you get reimbursed on your Apple account for an accidental charge related to purchasing a TV series in the wrong language?