Regular expressions: the shorter the string, the longer the time to analyse
Hello there !
I've got a problem with regular expressions...
I analyse those two strings with the same regular expression, searching for the "message" word.
The first of them, which is much longer than the other one, is instantly analysed... but the second one takes about to one second !
Do you see the problem ? (I do not, as you can guess...).
I tried to put the same special characters in the two ones... but it still works slowly for the second one.
This is instantly analysed:
"Coucou----- Origin.a.l. .message -----From: clems= To: Cl�ment S=ent: Wednes=day, April 30, 2003 1:38 PMSubject: Fw: mail de test----- Original Message -----From: clemsTo: Cl�ment Sent: Wednesday, April 30, 2003 1:37 PMSubject: mail de testcoucou, ceci est un mail de t.e.s.t... !!!Clems.".matches("((.*\\W)*\\Q" + "message" + "\\E(\\W.*)*)")
This takes about to one second:
"This is a b message ubodyub.brHere s a href= http:www.tano.fr.fm the second linea.".matches("((.*\\W)*\\Q" + crit�reActuel.getLeMot(i).toLowerCase() + "\\E(\\W.*)*)")
Pleaaase, help ;)
Clement
Well in fact everything seems to work... there was another problem...
My regular expression seems to be wrong and the code too...
I apologize... sorry for the waste of time.
See you later :) for my next wrong problem ! :))
Clement
Similar Messages
-
Framemaker uses <$filename> for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen? In compiling our books it would be helpful to not have this extension appear as it then requires us to create extra files without them.
See: System Variables
-
When trying to open lightroom I get a message that says, "The lightroom.exe that the short cut refers to has been changed or moved, so the short cut will no longer work properly. Do you want to remove this short cut? The program has opened and worked fine in the past.
You have (probably accidentally) moved or deleted the Lightroom program. You need to find it (have your operating system search for lightroom.exe) and move it back to where the shortcut expects it to be.
-
Log the local variables (string type) to the database (SQL Server)
i have a customized PreUUT callback so that my own VI gets the information from barcode. it contains serial number as well as other information. i am collecting the information into local variables of the PreUUT callback.
Now i want to log the local variables (string type) to the database (SQL Server).
i have a successful connection to the database and i am using a generic recordset schema.
can anyone help me how to do it?
also shall i have to create the corrosponding fields (columns) in the database? or is there any option in TestStand4.0 to do it?Hello i like original,
After re-reading your original message, I think I might have a better understanding of what you would like to do. I have included a few links to Knowledge Base and Developer Zone articles that should be very useful for you. I have included these links below:
Logging a New UUT Property to a Database in TestStand
Logging a New Step Property to a Database in TestStand
Creating a TestStand Database Schema from Scratch
Thanks,
Jonathan C
Staff Application Engineering Specialist | CTD | CLA
National Instruments -
Regular Expressions and Numbers in Strings
Looking for someone who has had experience in using Regular Expressions in the Classification Rule Builder.
We have an eVar that is collecting the number of search results in this fashion:
<Total Results>_<# of Item 1>_<# of Item 2>_<# of Item 3>_<# of Item 4>
Example output would look like this:
150_50_0_25_75
What we've done is initially create a Regular Expression that looks like this:
^(.+)\_(.+)\_(.+)\_(.+)\_(.+)$
The problem is, it appears in situations where the output contains a zero in one of the slots, the value is ignored and it receives the value in the next place over. Using the example output shown above, I would end up with values like this:
$0 150_50_0_25_75
$1 150
$2 50
$3 25
$4 75
$5 {null}
Here's the weird part. When I perform a test of a single record, it appears like it will work just fine, but when it actually runs in Omniture, it's not working as expected. Here's something else I'd like to know if it's possible to address. The five-place string is only the newest iteration of this approach. In the past, we started out with a two-place version, then three-place and then four. Any recommendations for handling all scenarios?
Any and all advice is welcome. Thanks in advance!Doing some playing around on rubular.com and thinking the Regular Expression should be build this way instead:
^(\d+)\_(\d+)\_(\d+)\_(\d+)\_(\d+)$
Again, still looking for any additional guidance from more experienced individuals. Thanks! -
How to write regular expression to find desired string piece *duplicate*
Hi All,
Suppose that i have following string piece:
name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
ali
mehmetI use following statement
SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
2 select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
3 );
LST NM
name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
Any ideas about regexp?
Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
Regards...
Mennan
Edited by: mennan on Jul 4, 2010 9:53 PM
thread was posted twice due to chrome refresfment. Please ignore the thread and reply to How to write regular expression to find desired string pieceThe approach is to do cartesian join to a 'number' table returning number of records equal to number of names in the string.I have hardcoded 2 but you can use regexp_count to get the number of occurrences of the pattern in the string and then use level <=regexp_count(..... .
See below for the approach
with cte as(
select
'name:ali#lastname:kemal#name:mehmet#lastname:cemal' col ,level lev
from dual connect by level <=2)
select substr(regexp_substr('#'||col,'#name:\w+',1,lev),7)
from cte
/ -
Is there a way to get the actual XML string when using the JAXP SAX Parser?
Hi All,
I am using a JAXP SAX xml parser and am looking for a way to get the actual line of xml that is being parsed from within a content handler.
Here's my scenario. Consider the following example xml document.
<formCollection>
<form name="myForm">
<text/>
<selection/>
</form>
<form name="anotherForm">
<text/>
</form>
</formCollection>My hope is to validate the entire document and then insert an xml string containing each "form" element (and its sub-elements) into a map for later use. My thought was to create a String as each "form" element is being parsed (begining with the form's startElement event and concatenating until the form's endElement event is reached) and then inserting this string into the map. Is there a way to get the actual line of xml that is being parsed, rather than just the element name and attribute values?DrClap wrote:
YouRang wrote:
2. The first handler would validate the entire XML document, extract the "type" attribute from each <form> element, and place each <form> element and its sub-elements into the map of Strings, using the "type" attribute as the key. The second handler would take a <form> element and parse it into a Form object for the display. This option was the impetus for my question because it relies on the first handler being able to access the entire <form> element XML String and write it to a map.I don't see why you need the raw data from the XML document here. You should already be abstracting your data into Java classes in the first handler, instead of making the second handler do the parsing all over again.Correct, I am not referring to XForms. In this case, it happens that I am using the XML to generate an SWT ScrolledForm object and, thus, the XML element name happens to be named "form." However, the concept/design problem could apply to any type of object and the XML element could be appropriately renamed.
My experience with XSLT is limited and I haven't done anything with it for several years. With that said, it seems that it is primarily used for generating web content, which wouldn't apply in this case because this is for a client-server application. I could be off base on this one -- if XSLT applies to much broader translations and would be more appropriate for generating Java objects than my current methodology, I could certainly look into it further.
I apologize that option two didn't make more sense; it is difficult to explain. Yes, optimally the data should be abstracted into Java classes in the first handler. This is really an elaboration that I failed to specify when explaining option one. The problem is that the user can choose to create any number of "forms" of any type. For instance, let's say that from the File -> New menu there are options for seven different types of forms and each form is used to send completely different data. The user can select form1, select form1 again, select form4, and select form7 (or any other combination) and bring up tabs that display the different forms. The user can then enter data and submit each form separately. When the user selects File -> New -> FormX, a SWT ScrolledForm object that corresponds with FormX must be given to the display. Because SWT ScrolledForm objects do not allow a deep copy, I cannot simply read the XML <form> elements at initialization, parse them into ScrolledForm objects, and pass deep copies of the ScrolledForm objects to the display each time the user clicks File -> New -> FormX. The only simple way I see of getting a new copy of a ScrolledForm object is to reparse the appropriate XML <form> element in order to create one each time the user selects File -> New -> FormX. As such, one handler would need to read the entire XML document and parse the <form> elements into a map (or some other data structure) and another handler would need to parse individual <form> elements into SWT ScrolledForm objects. The first handler would be called at initialization and the second handler would be called each time a user clicked on File -> New -> FormX. Once again, this isn't exactly my favorite implementation... but seems the simplest given that there is no way to do a deep copy of an SWT ScrolledForm object. Hopefully that makes a little more sense. No worries if it doesn't -- I just figured I'd throw this out there and see if anyone had a better idea. -
Getting the same return string while reading multiple times from a GPIB instrument
I'm having problems reading data from a GPIB instrument.
I'm using a sequence similiar to this:
1. Send a "MEASCALRES?" command to the calibrator to measure the current pressure.
2. Read the result string sent from the calibrator.
3. Send a "SYST:ERR:NEXT?" query to check if an error has occured.
4. Recieve the error string from the calibrator.
When running the program, the error string sometimes contains the same data as the pressure reading. For example, if the calibrator's pressure output string was "1.0000000e2", the error string might be "1.0000000e2" or sometimes just "20, No Errors", with the extra "2" added to the normal "0, No Errors".
The problem a
ppears to occure randomly, a rough estimate would be that it happens one time out of 50 readings.
Are there any relevant GPIB card settings I can change to fix the problem?It looks to me that more data is send or data end is signalled to early by hte iocard.
Maybe you should check the gpib bus cable speed. The default is much too fast for almost all instruments. Put it on 2 microseconds (the slowest speed). And we always disable autopolling, to prevent asynchronous actions.
greetings from the Netherlands -
I need the short key to go to the beginning of end timeline.
In the help (shortkey) i must use the home key to go to the beginnig of timeline but there is no home key on my macbpro...
What is the key (or shortkey) for this action and for the end of the timeline?
Thanks!You need to go to system Prefrences keyboard and see what you have set to show the desktop. It shouldn't be set to the fn key. Nothing should be set to just the fn key by itself.
-
Regular expression- insert into a string phrase "new" into correct position
I have sample data in table T below, and i have sample output how i want the query to output over that data.
with T as
select 'CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS' s from dual union all
select 'Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" IS' s from dual
select REGEXP_REPLACE(T.s, '^.PACKAGE BODY$','(\1)_new',1,1,'i') as s from T;
Expected output:
CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE_new" IS
Create OR REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO_new" IS
*/All data has following pattern:
CREATE OR REPLACE PACKAGE BODY "[owner]"."[name]" ISWhere [owner] can be any string. In sample data we have for example values XXX and YYY there.
And [name] can be any string. In sample data we have for example values PACKAGEONE and PACKAGETWO there.
Other parts of the string is fixed and stays as you see.
As shown in expected output query should replace substring "[owner]"."[name]" to "[owner]"."[name]_new"
How can i write such query?
I think i somehow should in regular expression count the positions of double quotes to achieve the expected result, but i don't know how.Thx, but your solution doesn't work, it doesn't put phrase "new" into string. I use Oracle 10g.
with T as
select 'CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS...' s from dual union all
select '...Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" ..."a"."b" procedure a IS..' s from dual
select
RegExp_Replace(s,'(" IS$)','_new\1') as new
from t;
CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS...
...Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" ..."a"."b" procedure a IS..
{code} -
Regular expression - parse version number string
Hi,
I try to parse a string using regular expressions but id did not work correctly in all cases.
The string that i want to parse can have one of the following layout:
3.4.5.v20090305 or
3.4.5The first three parts have to be integer values, the last part can be a free string (which is optional).
I use the following code to parse the version number and extract the parts:
Pattern versionPattern = Pattern.compile("(\\d+)\\.{1}(\\d+)\\.{1}(\\d+)(?:\\.{1}(\\w+))?");
Matcher m = versionPattern.matcher(versionString);
if (!m.find()) {
throw new IllegalArgumentException("Version must be in form <major>.<minor>.<micro>.<qualifier>");
// assert that we matched every part
// three groups (without qualifier) or four parts (with qualifier)
int groups = m.groupCount();
if (groups != 4) {
throw new IllegalArgumentException("Version must be in form <major>.<minor>.<micro>.<qualifier>");
// extract the parts
major = parseInt(m.group(1));
minor = parseInt(m.group(2));
micro = parseInt(m.group(3));
qualifier = m.group(4);The above regular expression works in all cases that i tested, except one.
The follwoing string is accepted as correct input: (but it shouldn't)
3.4.5a.v20090305And i get the result:
major = 3
minor = 4
micro = 5
qualifier = a.v20090305
Thanks for help or suggestions :)
Best Regards,
Michaelheissm wrote:
Hi,
I try to parse a string using regular expressions but id did not work correctly in all cases.
The string that i want to parse can have one of the following layout:
3.4.5.v20090305 or
3.4.5The first three parts have to be integer values, the last part can be a free string (which is optional).
I use the following code to parse the version number and extract the parts:
Pattern versionPattern = Pattern.compile("(\\d+)\\.{1}(\\d+)\\.{1}(\\d+)(?:\\.{1}(\\w+))?");
Matcher m = versionPattern.matcher(versionString);
if (!m.find()) {
throw new IllegalArgumentException("Version must be in form <major>.<minor>.<micro>.<qualifier>");
// assert that we matched every part
// three groups (without qualifier) or four parts (with qualifier)
int groups = m.groupCount();
if (groups != 4) {
throw new IllegalArgumentException("Version must be in form <major>.<minor>.<micro>.<qualifier>");
// extract the parts
major = parseInt(m.group(1));
minor = parseInt(m.group(2));
micro = parseInt(m.group(3));
qualifier = m.group(4);The above regular expression works in all cases that i tested, except one.
The follwoing string is accepted as correct input: (but it shouldn't)
3.4.5a.v20090305And i get the result:
major = 3
minor = 4
micro = 5
qualifier = a.v20090305No, that can't be the output. Perhaps you have some old class files you're executing, because with the code you now posted, that can't be the result.
To verify this, execute this:
import java.util.regex.*;
public class Main {
public static void main(String[] args) {
String versionString = "3.4.5a.v20090305";
Pattern versionPattern = Pattern.compile("(\\d+)\\.{1}(\\d+)\\.{1}(\\d+)(?:\\.{1}(\\w+))?");
Matcher m = versionPattern.matcher(versionString);
if (!m.find()) {
throw new IllegalArgumentException("Version must be in form <major>.<minor>.<micro>.<qualifier>");
// assert that we matched every part
// three groups (without qualifier) or four parts (with qualifier)
int groups = m.groupCount();
if (groups != 4) {
throw new IllegalArgumentException("Version must be in form <major>.<minor>.<micro>.<qualifier>");
// extract the parts
System.out.println("1 -> "+m.group(1));
System.out.println("2 -> "+m.group(2));
System.out.println("3 -> "+m.group(3));
System.out.println("4 -> "+m.group(4));
}and you'll see that the following is the result:
1 -> 3
2 -> 4
3 -> 5
4 -> nullSome remarks about your pattern:
"(\\d+)\\.{1}(\\d+)\\.{1}(\\d+)(?:\\.{1}(\\w+))?"All the "{1}" can be omitted they don't add anything to your regex and are only cluttering it up. And you'll probably also want to "anchor" your regex using the start- and end-of-string-meta-characters, like this:
"^(\\d+)\\.(\\d+)\\.(\\d+)(?:\\.(\\w+))?$" -
Regular expression for middle of string
Bit of background. I'm getting both text (can contain numbers) and data (only numbers) from serial. Since I don't know which I'm receiving and when it starts/ends, I'm making the sender send "textSTART###textSTOP" where "###" is what I want to extract. ### can contain text, numbers, new line, carrige return or whatever.
The same for data: "dataSTART###dataSTOP", where ### contains only numbers.
I think I should use Match Pattern, but I don't know how to make my regular expression.
Any help is appreciated.
Solved!
Go to Solution.If the string does not contain anything outside these "delimiters" and there are exactly two per string, you could simply use scan strings for tokens. You can also add the "dataSTART/STOP" delimiters to the array to make it universal and look at the beginning of the raw string to determine if you are dealing with a "data" or "text" message.
Here's a quick draft.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
TaggedText.png 10 KB -
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 expression or format into string (nevermind)
Solved it,
I can use string to fractional number!
Hi,
I have a 2D string array from a multicolumn list box, and i want to check if every value is valid number, the numbers can be a single and can have negative values. Does anyone knows which regular expression i need to check this, or is there an ever better way doing it?
Best regards,
Thijs
Solved!
Go to Solution.You shoudl post your solution so others who have a similar issue can learn from how you solved it.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot -
It was alot of small films in approximatly 10-20 minutes and it was alot of them, and i dont want to go back between the websites to start download them again because that took a lotof time.
If it happens again the make sure that you aren't suppressing website colors.
Make sure that you allow pages to choose their colors and that you haven't enabled High Contrast in the Accessibility settings.
*Tools > Options > Content : Fonts & Colors > Colors : [X] "Allow pages to choose their own colors, instead of my selections above"
*https://support.mozilla.org/kb/Options+window+-+Content+panel
*http://kb.mozillazine.org/Website_colors_are_wrong
*http://kb.mozillazine.org/Websites_look_wrong -
I'm having trouble downloading Mountain Lion from the app store with a long "waiting" time
I tried to download mountain lion from the app store, but it has been in the "waiting" mode on my desktop for some time... What should I do?
http://www.apple.com/support/mac/app-store/contact.html?form=account
Maybe you are looking for
-
Price Condition Depending of Material Master Record
Helllo Experts, I have an issue with a price condition on a price procedure the user wants to be able to mantain the price condition manually only if the material used at item level of sales order is equal to one of 3 sku´s. This Price condition can
-
Error in SMW01:Allocation of the tax for country RO, sequence 1, value 0 no
Hi, when materials are replicated we found a queue existing in SMQ1 and SMQ2. When i have checked in SMW01 for the Log it showed me the error "Allocation of the tax for country RO, sequence 1, value 0 not possible" Then i clicked on Show BDoc Message
-
Why do i get a black screen when i open a pdf file?
why do I get a black screen when I open a pdf file?
-
Hi, One of our PMs is trying to change a task in his project plan and gets the following message: "cannot delete or reassign tasks or assignments with protected actuals" . This would normally be ok since we have setup actual work to be reported only
-
Is there some sort of BC textbook?
I found one on Amazon but it's a couple of years old and is getting bad reviews for being outdated. I love BC, but it sucks having to look everything you need to know up individually on different websites or googling or youtubing. I'd be nice to ha