XQuery tokenize() regular expression not interpreting correctly?

I've been trying to use XQuery tokenize() with a regular expression as an argument.
Given the string
S831409 $50 070886
(Note: 3 spaces at the end.)
And the expression
\b(\w+)\b
to find words on word boundaries
and using java.util.regex functions Pattern() and Matcher(), this is returned:
S831409
50
070886
without leading or trailing spaces.
Using the XQuery:
depositAmt =
{snip}
return
let $fndWord := xf:tokenize($locVal, "\b(\w+)\b")
return $fndWord[2]
I would expect to get
depositAmt="50"
Instead I get
depositAmt=" $"
Okay, changing the return to
$fndWord[3]
I get
depositAmt=" "
Changing the return to
$fndWord
gets
depositAmt=" $ "
Changing the regEx to
\b\s+\b
improves things somewhat, but not much.
Am I missing something?

The pattern that is supplied to tokenize() function is used to indicate the SEPARATOR. So the pattern given to the function must match the separator instead of the content that you want. So you must think in the opposite.
For your case try to use [^\w]+ as the pattern. I think it should give you the same result.
Good luck

Similar Messages

  • Match Regular Expression not returning submatches.

    I am having an issue with Match Regular Expression not returning the appropriate number of submatches.  My string is as follows:
    DATAM    995000    1.75    0.007    -67.47    24.493    99.072
    The spaces are tabs and the length is not fixed so simple string manipulation is out of the question.  The regular expression I was trying is as follows:
    (?<=\t)[0-9\.\-]*(?=(\t|$))
    It successfully returns Whole Match as the first number but no submatches are returned.  I've tried simpler expressions which work in Matlab and EditPad Pro such as [0-9.-]* but never got the same answer in Labview.
    What is going on?

    Here is an image of the VI.  The top portion is the input from our Licor 7000.  The bottom portion is the bit of code I'm having problems with.
    Attachments:
    matchregularexpression.jpg ‏336 KB

  • Unix Log Monitoring regular expression not picking up alerts

    Hi,
    We are moving our unix monitoring to SCOM 2012 SP1 rollup 4.
    What I have got working is indvidual alert logging of Unix Log alerts by exporting the MP and changing the <IndividualAlerts> value to true and removing the suppression xml section then reimporting the MP.
    What I am trying to do is use the regular expression to peform the suppression of specific event (such as event codes).
    The expression is:
    ((?i:warning)(?!(.*1222)|(.*1001)))
    ie Search the log for "warning" (not case sensitive) then check if events 1222 or 1001 exist if so return no match, if they dont exist then return true. 
    I use the built in test function in SCOM when creating the rule and the tests come back as expected but when I inject test lines into the unix log, no alerts get generted.
    I suspect it could be the syntax not being accepted on the system (its running RedHat 6 )
    I have tested this with regex tools and works.
    When I try and test it on the server i get:
    [root@bld02 ~]# grep ((?i:Warning)(?!(.*1222)|(.*1001))) /var/log/messages
    -bash: !: event not found
    [root@bld02 ~]# tail /var/log/messages
    Nov 13 15:07:26 bld02 root: SCOM Test Warning Event ID 1001 Round 18
    Nov 13 15:07:29 bld02 root: SCOM Test Warning Event ID 1000 Round 18
    Nov 13 15:07:35 bld02 root: SCOM Test Warning Event ID 1002 Round 18
    So I am expecting 2 alerts to be generated.
    SCOM tests to show expression working:
    Test 1 Matching
    Test 2 to exclude
    Need some help with this, Thankyou in advance :)

    Hello,
    Here's an example of modifying the MP to exclude particular events.  Firstly, I created a log file rule using the MP template that is fairly inclusive - matching the string Warning (with either a lower or upper case W).
    I then exported the MP, and modified the rule.  I set the IndividualAlerts = true and removed the AlertSuppression element, so that every matched line will fire a unique alert.  You don't have to remove the AlertSuppression, but you should use
    Individual alerts so that the exclusion logic doesn't exclude concurrent events that you actually want to match.
    Implementing the exclusion logic involves the addition of a System.ExpressionFilter definition in the rule. This will use a conditional evaluation of the //row element of the data item.  Here's an example of a dataitem matching an individual row:
    <DataItem type="System.Event.Data"time="2013-11-15T10:33:14.8839662-08:00"sourceHealthServiceId="667FF365-70DD-6607-5B66-F9F95253B29F">
    <EventOriginId>{86AB962D-2F44-29FD-A909-B99FF6FEB2C5}</EventOriginId>
    <PublisherId>{EC7EA4B1-0EA5-7E8E-701F-82FEF3367BC4}</PublisherId>
    <PublisherName>WSManEventProvider</PublisherName>
    <EventSourceName>WSManEventProvider</EventSourceName>
    <Channel>WSManEventProvider</Channel>
    <LoggingComputer/>
    <EventNumber>0</EventNumber>
    <EventCategory>3</EventCategory>
    <EventLevel>0</EventLevel>
    <UserName/>
    <RawDescription>Detected Entry: warning 1002</RawDescription>
    <CollectDescription Type="Boolean">true</CollectDescription>
    <EventData>
    <DataItem type="SCXLogProviderDataSourceData"time="2013-11-15T10:33:14.8839662-08:00"sourceHealthServiceId="667FF365-70DD-6607-5B66-F9F95253B29F">
    <SCXLogProviderDataSourceData>
    <row>warning 1002</row>
    </SCXLogProviderDataSourceData>
    </DataItem>
    </EventData>
    <EventDisplayNumber>0</EventDisplayNumber>
    <EventDescription>Detected Entry: warning 1002</EventDescription>
    </DataItem>
    Here is the rule in the MP XML.  The <ConditionDetection>...</ConditionDetection> content was what I added to do the exclusion filtering:
    <Rule ID="LogFileTemplate_66b86eaded094c309ffd2631b8367a32.Alert" Enabled="false" Target="Unix!Microsoft.Unix.Computer" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
    <Category>EventCollection</Category>
    <DataSources>
    <DataSource ID="EventDS" TypeID="Unix!Microsoft.Unix.SCXLog.VarPriv.DataSource">
    <Host>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/PrincipalName$</Host>
    <LogFile>/tmp/test</LogFile>
    <UserName>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$</UserName>
    <Password>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$</Password>
    <RegExpFilter>warning</RegExpFilter>
    <IndividualAlerts>true</IndividualAlerts>
    </DataSource>
    </DataSources>
    <ConditionDetection TypeID="System!System.ExpressionFilter" ID="Filter">
    <Expression>
    <RegExExpression>
    <ValueExpression>
    <XPathQuery Type="String">//row</XPathQuery>
    </ValueExpression>
    <Operator>DoesNotContainSubstring</Operator>
    <Pattern>1001</Pattern>
    </RegExExpression>
    </Expression>
    </ConditionDetection>
    <WriteActions>
    <WriteAction ID="GenerateAlert" TypeID="Health!System.Health.GenerateAlert">
    <Priority>1</Priority>
    <Severity>2</Severity>
    <AlertName>Log File Alert: ExclusionExample</AlertName>
    <AlertDescription>$Data/EventDescription$</AlertDescription>
    </WriteAction>
    </WriteActions>
    </Rule>
    I traced this with the Workflow Analyzer as I tested, which shows the logic being applied.  Here is the exclusion happening:
    Here's more info on the definition of an ExpressionFilter:
    http://msdn.microsoft.com/en-us/library/ee692979.aspx
    And more information on Regular Expressions in MPs:
    http://support.microsoft.com/kb/2702651/en-us
    You can also have multiple Expressions in the ExpressionFilter joined by OR or AND operators.
    Also, if you are comfortable with the MP authoring, you can just skip the step of creating the rules in the MP template and just author your own MP with the VSAE tool:
    http://social.technet.microsoft.com/wiki/contents/articles/18085.scom-2012-authoring-unixlinux-log-file-monitoring-rules.aspx
    www.operatingquadrant.com

  • br tag in bean value not interpreted correctly

    Hi all
    i want to display a long string which includes <br> tags. This string is saved in a bean. In my JSP page i try to diplay the string as follows:
    <bean:write name="logFileText"/>
    This works but the <br> tags are not rendered/interpreted correctly. The display String look like that:
    21/09/2004 10:01:44 [INFORMATION] [init/process] 0001 Starting ... (at line 124 in file ndl_main.cxx)<br>21/09/2004 10:01:44 [INFORMATION] [init/undefined] 0010 Start Initialization (at line 109 in file ndl_dataloader.cxx)<br>21/09/2004
    If i take a look at the page source the <br> is written there as lt;br gt . But i want to go to a new line instead of displaying the <br> tag.
    Could somebody help me with that?
    Thanks Angela

    seems it doesn't work like that:
    [ServletException in:/pages/log/listLogFile.jsp] /pages/log/listLogFile.jsp(13,4) Attribute escapeXml invalid for tag write according to TLD'

  • CSS not interpreted correctly

    Safari does not interpret standard CSS correctly, but Firefox 1.5, Netscape 7.2 and Opera 9.01 do. Safari does not understand the CSS width and height declarations.
    Is there a workaround?
    How does my page look on a Windows computer with a popular browser?
    Is there any hope that a later version of Safari will understand CSS?
    See the
    tag in <http://homepage.sunrise.ch/homepage/nicoletf/index.html> and the correcsponding CSS declaration in <http://homepage.sunrise.ch/homepage/nicoletf/Muotathal/stylesheets/index2.css>.
    iMac G3, iBook G4, PowerBook G4   Mac OS X (10.4.7)  

    A little correction to your post:
    The width and height properties only fail on images, to all other attributes the CSS values for width and height will just work.
    This bug or "missing feature" has been added in the latest open-source version of the rendering engine. (For download available via: http://nightly.webkit.org/ ). Also OmniWeb 5.5b will support this feature and it will most likely be standard supported in Leopard.

  • ReplaceAll string by regular expression not work for this case.

    I will delete all tag and want "pure text" but the output is delete all.
    String content = "<aaa>pure text<fff>";
    content = content.replaceAll("<.*>","");Content has output is blank because reqular expression match from begin and end of string
    But when i change
    String content = "<aaa>pure text<fff";
    content = content.replaceAll("<.*>","");The output is ==> pure text<fff
    How make req match in sequential
    Please lead me to solution

    peterdog1234 wrote:
    Thank you very much.
    I know '?' is a Quantifiers.
    I do not understand using ?
    Please lead me againSee the paragraph "Laziness Instead of Greediness" from [http://www.regular-expressions.info/repeat.html].

  • CFFORM (Flash) Validation with Regular Expressions Not Working

    I am having troubles getting regular expression validation to
    work in a CFFORM. The below code is an extract of a much larger
    form, the first name and last name have a regular expression
    validation...and it doesn't work!
    I'd appreciate any comments/info for help on this, have
    searched high and low on information to get this working...but no
    joy.
    The code is:
    <cffunction name="checkFieldSet" output="false"
    returnType="string">
    <cfargument name="fields" type="string" required="true"
    hint="Fields to search">
    <cfargument name="form" type="string" required="true"
    hint="Name of the form">
    <cfargument name="ascode" type="string" required="true"
    hint="Code to fire if all is good.">
    <cfset var vcode = "">
    <cfset var f = "">
    <cfsavecontent variable="vcode">
    var ok = true;
    var msg = "";
    <cfloop index="f" list="#arguments.fields#">
    <cfoutput>
    if(!mx.validators.Validator.isValid(this,
    '#arguments.form#.#f#')) { msg = msg + #f#.errorString + '\n';
    ok=false; }
    </cfoutput>
    </cfloop>
    </cfsavecontent>
    <cfset vcode = vcode & "if(!ok)
    mx.controls.Alert.show(msg,'Validation Error'); ">
    <cfset vcode = vcode & "if(ok) #ascode#">
    <cfset vcode =
    replaceList(vcode,"#chr(10)#,#chr(13)#,#chr(9)#",",,")>
    <cfreturn vcode>
    </cffunction>
    <cfform name="new_form" format="flash" width="600"
    height="600" skin="halosilver" action="new_data.cfc">
    <cfformgroup type="panel" label="New Form"
    style="background-color:##CCCCCC;">
    <cfformgroup type="tabnavigator" id="tabs">
    <cfformgroup type="page" label="Step 1">
    <cfformgroup type="hbox">
    <cfformgroup type="panel" label="Requestor Information"
    style="headerHeight: 13;">
    <cfformgroup type="vbox">
    <cfinput type="text" name="reqName" width="300"
    label="First Name:" validate="regular_expression" pattern="[^0-9]"
    validateat="onblur" required="yes" message="You must supply your
    First Name.">
    <cfinput type="text" name="reqLname" width="300"
    label="Last Name:" validate="regular_expression" pattern="[^0-9]"
    validateat="onblur" required="yes" message="You must supply your
    Last Name.">
    <cfinput type="text" name="reqEmail" width="300"
    label="Email:" validate="email" required="yes" message="You must
    supply your email or the address given is in the wrong format.">
    <cfinput type="text" name="reqPhone" width="300"
    label="Phone Extension:" validate="integer" required="yes"
    maxlength="4" message="You must supply your phone number.">
    </cfformgroup>
    </cfformgroup>
    </cfformgroup>
    <cfformgroup type="horizontal"
    style="horizontalAlign:'right';">
    <cfinput type="button" width="100" name="cnt_step2"
    label="next" value="Next"
    onClick="#checkFieldSet("reqName,reqLname,reqEmail,reqPhone","new_form","tabs.selectedInd ex=tabs.selectedIndex+1")#"
    align="right">
    </cfformgroup>
    </cfformgroup>
    </cfformgroup>
    </cfformgroup>
    </cfform>

    quote:
    Originally posted by:
    Luckbox72
    The problem is not the Regex. I have tested 3 or 4 different
    versions that all work on the many different test sites. The
    problem is it that the validation does not seem to work. I have
    changed the patter to only allow NA and I can still type anything
    into the text box. Is there some issue with useing Regex as your
    validation?
    Bear in mind that by default validation does not occur until
    the user attempts to submit the form. If you are trying to control
    the characters that the user can enter into the textbox, as opposed
    to validating what they have entered, you will need to provide your
    own javascript validation.

  • Regular expression not working for adobe forms

    Hi,
    Iam using qtp for adobe forms and for some reason if i put in regular expression for apid value it doesn't recognise the object..there is nothing wrong with the regular expression as it is evaluated using regular expression evaluator in qtp 11.0....any ideas
    I got all the addins and everything and when i used regular expression for the top window it works but for any other object it doesn't

    Please try the code and see the problem. The regular expression is fine.
    I can replace the string with these and got results like this:
    import java.util.regex.Pattern;
    public class HtmlFilter implements TextFilter {
        private static String strTagPattern = "<\\s?(.|\n)*?\\s?>";
        private static int patternMode = Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.CANON_EQ;
        private static Pattern tagPattern = Pattern.compile(strTagPattern, patternMode);
        public String filter(String t) {
              if(t==null || t.length()==0) return "";
            String ret = null;
            return tagPattern.matcher(t).replaceAll("");
         public static void main(String[] args) {
              System.out.println(new HtmlFilter().filter(null));
              System.out.println(new HtmlFilter().filter(""));
              System.out.println(new HtmlFilter().filter("<P>abc def</P>"));
              System.out.println(new HtmlFilter().filter("<P>&#25105;&#22269;&#30707;&#27833;&#20379;&#24212;&#23433;&#20840;&#31995;&#32479;&#24433;&#21709;</P>"));
    }The results are
    abc def
    ????????????

  • Regular expression not giving the required output.

    Hi , I have msgs that look like this :
    dear john smith you Bought 500 shares of Nile Cotton Ginning at 14.9 L.E On 21/01/10
    Im using the Regular expression to get 4 substrings of this msg
    1-Bought|Sold
    2-Quantity of shares (ex: 500)
    3-Name of the stock (ex:Nile Cotton Ginning)
    4-price (ex:14.9)
    Here is my code , but the output returns the whole msg back :
    select SMSID,SMSNO,CUSTOMERACCOUNTID,SENDDATE,ENTRYDATE,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\1')),'(watheeqa)') buy_sell
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\2')),'(watheeqa)') amount ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\3')),'(watheeqa)') company ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at ([0-9]*\.[0-9]*|[0-9][^A-Z][^a-z]) .*','\4')),'(watheeqa)') price
    from SMSOUTMSG@bimsic s
    where trunc(SENDDATE) = trunc(sysdate) -1
    and exists (select 1 from PHONEDETAIL@bimsic p
                where s.CUSTOMERACCOUNTID = p.CUSTOMERACCOUNTID
                and SMSFLAG = 1);Thanks.

    It does check it out
    with t
    as
    select 'dear john smith you Bought 500 shares of Nile Cotton Ginning at 14.9 L.E On 21/01/10' smstext from dual
    select
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\1')),'(watheeqa)') buy_sell,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\2')),'(watheeqa)') amount ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\3')),'(watheeqa)') company ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at ([0-9]*\.[0-9]*|[0-9][^A-Z][^a-z]) .*','\4')),'(watheeqa)') price
    from t

  • Time Capsule and Airport Express not working correctly.

    Just bought a Time Capsule to replace my router....and now my Airport Express is no longer showing up in Airport Utility.
    Also, the speed is awful.  I have 25MB coming into the house via ethernet....but a speedtest on my wireless network shows me running at 4.5Mb download speed.
    I spent $500 on the Time Capsule.  I don't understand it.
    Anyone have suggestions?
    Tony

    I would suggest, reconnecting the Express to the TC again. Use the AirPort Utility to make ALL configuration changes including the network extending settings. Then restart both base stations and check that the settings are still good. Then disconnect the Express and give it a few minutes to initialize. It should connect. If not, then the issue may be either the distance or obstructions (like walls, ceilings, floors, etc.) that is preventing the Express from getting a signal from the TC that is adequate enough to extend.

  • Newline feed not interpreted correctly by Java

    In my project, rexx passes data to lotus notes thru mqseries. These data has newline feed characters. here java is used to read data from mqseries and create documents in lotus.
    now my problem is, this newly created document is showing some junk character instead of giving newlind-feed. so my doc is messed up.

    May I know what specific output stream you used?Have
    you try this to your output stream String
    newLine = (String)
    java.security.AccessController.doPrivileged(newsun.security.action.GetPropertyAction("line.separator"
    ));?-Ronillo.Why are you using sun internal classes? You shouldn't
    do that. You should just call
    System.getProperty("line.separator"), or am I missing
    something?
    (But it's even better to just use a BufferedWriter,
    it uses the correct newline by default)
    /KajSee my second reply, the buffered writer docs API. Im sorry. God bless you ^_^
    -Ronillo.

  • Airport Express Not Capturing Correct IP Address

    I've had my iMac G5 for about 18 months. I access the Internet via a cable modem. Last night I lost the ability to access the Internet.
    A Comcast technician walked me thru various steps and determined that my modem and computer were working fine, and that I could connect to the Internet when the modem was directly connected via an Ethernet connection to the computer, minus the Airport Express.
    Further diagnosis revealed that when connected to the Airport Express, the computer was receiving an incorrect IP address (10.0.1.2) when it should have captured 69.242.229.136 at the time. I'm set for Using DHCP, as necessary. I did resets to the Airport Express but it continues to capture and send the same 10.0.1.2 IP address. The end result is that I can't access the Internet.
    Can you help?
    iMac G5 with Airport Express and D-Link Modem   Mac OS X (10.4.5)  

    Below is the online manual for the AE. So you have been using the AE to access the Internet for 18 months and then last night .... poof? If so, use the assistant like they say to configure it. You could also change your Airport card configuration to accept DHCP and let the AE give you that address. Your computer has two ways to connect, so you may be mixing up the wired with the wireless. Wired you would get the 69.xxx.xxx.xxx and wireless you would accept the address from the AE ( use DHCP ) on your AirPort card on your MAC.
    http://manuals.info.apple.com/en/AirPortExpressSetupGuide.pdf
    Michael

  • Regular expression not working for String.split()?

    hi, i have a String variable called 'table'.
    It has a bunch of chunks of data seperated by whitespace, whether it
    be spaces or carraige returns. Anyways, i want to split this up using
    the String.split function. i want to split it around whitespace.
    here is my code:
    String codes[] = table.split("\s");
    However, i'm getting back all nulls in the codes variable. What am i doing wrong?
    thanks

    split("\\s")\ is special both in Java String literals and in regex, so you need two of them.
    You'll probably also have to take an extra step it you don't want regex to stop at newlines. I forget the details, so check the docs.

  • Safari May Not Interpret Regular Expression in Compliance with W3C Standard

    We are troubleshooting why some websites are no longer working when rendered with the Safari 2.0.4 browser. The failure begins when client entered data is validated using regular expressions.
    We have localized the issue to Safari's not interpretting regular expressions consistently.
    For example:
    Does the regex \u00e9 match the literal character é? (Validates the regular expression engine understands Unicode escape sequences for extended characters.)? - NO, but it does on IE and FireFox
    Does the regex \u0041 match the literal character A? (Validates the regular expression engine understands Unicode escape sequences for ASCII characters.)? - NO, but it does on IE and FireFox
    Does the regex é match the literal character é? (Validates the regular expression engine understands literal characters outside the ASCII range – this is against ECMAScript spec.)? - Sometimes, but always on IE and FireFox
    Write a Unicode escape sequence to the screen on the client side. (Validates the string parsing and display in the JS engine works.) - Works on all 3
    Is escape sequence \u00e9 equivalent to literal character é? (Validates the string functionality in the JS engine works with extended characters.)? Yes on all 3.
    Is escape sequence \u0041 equivalent to literal character A? (Validates the string functionality in the JS engine works with ASCII characters.)? Yes on all 3
    Does the regex A match the literal character A? (Validates the regular expression engine understands literal characters in the ASCII range – this is ECMAScript spec.)? Yes on all 3
    Please help. It's hard for me to believe that the regular expression / javascript interpreter(s) for Safari aren't working as they have in the past - but all roads are pointed that way....
    Thank you for your review.
      Mac OS X (10.4.7)  

    We are troubleshooting why some websites are no longer working when rendered with the Safari 2.0.4 browser. The failure begins when client entered data is validated using regular expressions.
    We have localized the issue to Safari's not interpretting regular expressions consistently.
    For example:
    Does the regex \u00e9 match the literal character é? (Validates the regular expression engine understands Unicode escape sequences for extended characters.)? - NO, but it does on IE and FireFox
    Does the regex \u0041 match the literal character A? (Validates the regular expression engine understands Unicode escape sequences for ASCII characters.)? - NO, but it does on IE and FireFox
    Does the regex é match the literal character é? (Validates the regular expression engine understands literal characters outside the ASCII range – this is against ECMAScript spec.)? - Sometimes, but always on IE and FireFox
    Write a Unicode escape sequence to the screen on the client side. (Validates the string parsing and display in the JS engine works.) - Works on all 3
    Is escape sequence \u00e9 equivalent to literal character é? (Validates the string functionality in the JS engine works with extended characters.)? Yes on all 3.
    Is escape sequence \u0041 equivalent to literal character A? (Validates the string functionality in the JS engine works with ASCII characters.)? Yes on all 3
    Does the regex A match the literal character A? (Validates the regular expression engine understands literal characters in the ASCII range – this is ECMAScript spec.)? Yes on all 3
    Please help. It's hard for me to believe that the regular expression / javascript interpreter(s) for Safari aren't working as they have in the past - but all roads are pointed that way....
    Thank you for your review.
      Mac OS X (10.4.7)  

  • Java – Regular Expressions – Finding any non digit byte in a multiple byte

    Hello,
    I’m new to JAVA and Regular Expressions; I’m trying to write a regular expression that will find any records that contain a non digit byte in a multiple byte field.
    I thought the following was the correct expression but it is only finding records that contain “all” non digit bytes.
    \D{1,}
    \D = Non Digit
    {1,} = at least 1 or more
    Below is my sample data. I would like the regular expression to find all of the records that are not all numeric. However when I use the regular expression \D{1,} it is only finding the 2 records that all bytes are non digits. (i.e. “ “ and “A “)
    “ 111229”
    “2 111229”
    “20091229”
    “200912c9”
    “201#1229”
    “20101229”
    “20110229”
    “20111*29”
    “20111029”
    “20111229”
    “20B11229”
    “A “
    “A0111229”
    Please note I have also tried \D{1,}+ and \D{1,}? And they also do not return my desired results
    Any assistance someone can provide would be greatly appreciated.

    You don't show the code you are using but I surmise you are using String.matches() which requires that the whole target must match the regular expression not just part of it. Instead you should create a Pattern and then a Matcher and use the Matcher.find() method. Check the Javadoc for Pattern and Matcher and look at the Java regex tutorial - http://docs.oracle.com/javase/tutorial/essential/regex/ .
    P.S. You can re-use the Pattern object - you don't have to create it every time you need one.
    P.P.S. Java regular expressions work with characters not bytes and characters are not not not bytes.

Maybe you are looking for