Pattern Match

Please help! I'm trying to write a piece of code to check if the string read from a file matches the format
"XXX-XXXX", where X should be a numeric value 0 thru 9. Basically I'm trying to make sure that user has sent the telephone number in the specified format.Thanks in advance.

Upgrade to 1.4.2 and then this will work.
import java.util.regex.*;
class Test
     public static void main(String[] args)
          for(int i = 0; i<args.length;i++)
               System.out.println(args[i]+" "+Pattern.matches("\\d\\d\\d\\-\\d\\d\\d\\d", args));
          System.exit(0);
Otherwise convert the string to a char[] and test that you have 8 characters, ch[3] is '-' and the rest are between '0' and '9'.
tokenizing the string on '-' and trying to make integers will allow some invalid phone number to pass. You will have to at least confirm that the numbers aren't negative and have the right number of digits.

Similar Messages

  • How do I set multiple pattern matching Vi's and make overlappin​g pattern matches to count as one?

    Hello! I'm a student and I'm currently making a project using pattern matching.
    My patterns are from chick foot/feet.
    I'm  created multiple pattern matching VI's to detect all the feet because I find it difficult/impossible to match all the feet with a single pattern/template.
    However, when using multiple pattern matching VI's some pattern matches detect the same foot, hence overlapping.
    So how can I make the overlaping pattern matches to be counted as one?
    Thank you in advance

    Thank you for replying Sir Zwired1.
    I'm still a newbie in using LabVIEW so pardon me if I can't understand fully
    The objective of my project is to detect all the feet through pattern matching and count the pattern matches made.
    "Keep a 2D array of counts, initialized to zero and the same size as your array of possible locations, and increment the value every time you get a match. If multiple pattern matching attempts result in a match a given location in your count array might be "3" but all you care about is if the number is greater than zero."
    I'm sorry, but how do you do this? BTW, I'm using vision assistant.

  • Trouble using a pattern match in the GO URL when the value starts with %

    Hi guys,
    We are trying to use a Go URL as follows:
    [http://hostname.com:9704/analytics/saw.dll?Go&Path=/users/administrator/Test/TestReport&Action=Navigate&col1=TestReport.SUBJECT&op1=like&val1="%25D8D8%25"|http://hostname.com:9704/analytics/saw.dll?Go&Path=/users/administrator/Test/TestReport&Action=Navigate&col1=TestReport.SUBJECT&op1=like&val1="%25D8D8%25"]
    Basically, we want to send the filter : SUBJECT like '%D8D8%' in the GoURL. However, the report that opens up does not fetch any rows because BI somehow messes up the clause by not recognizing the leading %25 (which is an escaped % character). Instead it resolves the %25D8D8%25 into something like �D8% .
    As you can see, the %25 at the end however gets resolved correctly but somehow the one at the beginning gets clubbed with the leading D8 to give �.
    Any idea, how to get BI to accept a leading escaped % character when doing a pattern match in the Go URL?

    I'm heading to the Apple Store in Danbury CT tomorrow to test out a MacBook Pro. I'll happily post what I like and dislike here.
    Waiting for a MacBook Pro...   Other OS  

  • How can I read a template and differentiate if it is a pattern matching template or a geometric matching template?

    Hey all,
    I would like to know how can I read a template´s information to know if it is a pattern macthing or a geometric matching template? 
    In my code, users provide templates and the algorithm must match them using pattern matching or geometric matching depending on the template.
    At the moment I am doing it by including a P or a G in the name of the file, but I would like to avoid this and read the information from the file.
    Any ideas?
    Thanks in advance,
    Esteban
    Solved!
    Go to Solution.

    Hey Esteban,
    you can use the VI "IMAQ Is Vision Info Present 2 VI" to reice the information:
    IMAQ Is Vision Info Present 2 VI - NI Vision 2011 for LabVIEW Help - National Instruments
    http://zone.ni.com/reference/en-XX/help/370281P-01/imaqvision/imaq_is_vision_info_present_2/
    Take a look at the attached VI
    Stephan
    Attachments:
    Determine Pattern type.zip ‏13 KB

  • OBIEE 11G : Remove label (is like pattern match) in the prompt

    Hi Experts,
    I have Gone through this thread Re: OBIEE 11G : Remove label (is like pattern match) in the prompt and applied JS as mentioed but
    It works for the first display of the page but its back as soon as you hit the apply button
    can be it be removed permanently? Thanks in Advance

    Hi Nagen,
    You can try the following:
    Create a variable prompt with the column vales that you want to match
    Create a filter in the analysis criteria tab on the column, set to pick up the variable, and define the IS LIKE here.
    It is effectively doing the same task as the standard prompt approach does, but in a round-a-bout way which doesn't include adding any of Oracle's text in.

  • Is there a way to turn the pattern matching example in Labview to instead of loading a rectangle around what you want the template to be you can use an image display , I've be trying and can get no where with it

    What I want to do is , have two images on image displays and the pass them through the same setup as the pattern matching example to get the number of matches , I have attached what I have done and also given the pattern matching example program as well.
    Hope to get answers back soon,
                                     Thanks Alan
    Attachments:
    screenshot.docx ‏48 KB
    Pattern Matching Example.vi ‏100 KB

    Hi there!
    The example used can be adapted for comparing two images, however the algorithm and coding for finding the differences is more specific to your actual problem. In terms of the loading and displaying of the images, this can be done in the same way.
    Once you have some sort of algorithm, then you can automate the learning and matching by simply wiring them in order. (in the example, these are put in case structures as they are waiting on response from the front panel)
    I hope that this helps,
    Liam A.
    National Instruments
    Applications Engineer

  • Regular Expressions (Pattern/Matcher) --- Help

    Hi,
    I have an regex i.e. Pattern.compile("([0-9])D([0-9])'?(?:([0-9]+)\")?([NSEW])").{code}
    It has to exactly match the input e.g *45D15'34"N*
    I need to retrieve the values based on grouping.
    Group1 = 45 (degree value)
    Group2 = 15 (minutes value)
    Group3 = 34 (seconds value) ----> this is a non-capturing group
    Group4 = N (directions)
    The regex works fine for most of longitude/latitude value but I get a StackOverFlow for some. There is a known bug on this http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507
    According to the bug report, they have said that are many different regex that can trigger the stack overflow....even though the length of my input is not as long as the one posted on the bug report.
    I was wondering if anyone could suggest a different way of writing the regex above to avoid the stack over flow.
    Thank you in advance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi,
    I missed the '+' in my original regex Pattern.compile("([0-9]+)D([0-9]+)'?(?:([0-9]+)\")?([NSEW])"){code}.
    I have also tried {code} Pattern.compile("(\\d+)D(\\d+)'?(?:(\\d+)\")?([NSEW])");And, the other 2 expressions as suggested by you.
    The problem happens when Durham Lat=”35D52’N” Lon=”78D47’W value is selected from a Jtree(the values are parsed from a xml file to the tree - the xml file has a bout 800 longitude/latitude elements for different cities in the US). It does not happen for other values and If I increment the degree or min by, then the expression works. I am not sure how else i could re-write this exp.
    Below is the snippet of the xml file:
    <State name="NORTH CAROLINA">
                <City name="Asheville AP"     Lat="35D26'N"     Lon="82D32'W"/>
                <City name="Charlotte AP"     Lat="35D13'N"     Lon="80D56'W"/>
                <City name="Durham"     Lat="35D52'N"     Lon="78D47'W"/>
                <City name="Elizabeth City AP"     Lat="36D16'N"     Lon="76D11'W"/>
                <City name="Fayetteville, Pope AFB" Lat="35D10'N"     Lon="79D01'W"/>
                <City name="Goldsboro,Seymour-Johnson"     Lat="35D20'N"     Lon="77D58'W"/>
                <City name="Greensboro AP (S)"     Lat="36D05'N"     Lon="79D57'W"/>
                <City name="Greenville"     Lat="35D37'N"     Lon="77D25'W"/>
                <City name="Henderson"     Lat="36D22'N"     Lon="78D25'W"/>
                <City name="Hickory"     Lat="35D45'N"     Lon="81D23'W"/>
                <City name="Jacksonville"     Lat="34D50'N"     Lon="77D37'W"/>
                <City name="Lumberton"     Lat="34D37'N"     Lon="79D04'W"/>
                <City name="New Bern AP"     Lat="35D05'N"     Lon="77D03'W"/>
                <City name="Raleigh/Durham AP (S)"     Lat="35D52'N"     Lon="78D47'W"/>
                <City name="Rocky Mount"     Lat="35D58'N"     Lon="77D48'W"/>
                <City name="Wilmington AP"     Lat="34D16'N"     Lon="77D55'W"/>
                <City name="Winston-Salem AP"     Lat="36D08'N"     Lon="80D13'W"/>
            </State>
    public final class GeoLine {
        /* Enum for the possible directions of longitude and latitude*/
        public enum Direction {
            N, S, E, W;
            public boolean isLongitude() {
                return (this == E || this == W);
            public boolean isLatitude() {
                return (this == N || this == S);
            public Direction getCanonicalDirection() {
                if (this == S) {
                    return Direction.N;
                } else if (this == W) {
                    return Direction.E;
                } else {
                    return this;
        private final int degree;
        private final int minute;
        private final int second;
        private final Direction dir;
        /* Recognizes longitude and latitude values that has degrees, minutes and seconds i.e. "45D15'34"N
        * or "45D1534"N. The single-quotes for the minutes is optional. And, for the moment we do not support seconds
        * validation although ilog library returns the longitude/latitude with second when NEs and Sub-networks are
        * dragged and dropped on the map.*/
    private static final Pattern PATTERN = Pattern.compile("([0-9]+)D([0-9]+)'?(?:([0-9]+)\")?([NSEW])");
        public GeoLine(int degree, int minute, Direction dir) {
            this(degree, minute, 0, dir);
        public GeoLine(int degree, int minute, int second, Direction dir) {
            Log.logInfo(getClass().getSimpleName(), "PAU degree: " + degree + " minute: " + minute + " second: " + second + " direction: " +  dir);
            verifyLongitudeLatitude(degree, dir);
            verifyMinute(degree, minute, dir);   
            this.degree = degree;
            this.minute = minute;
            this.second = second;
            if (this.degree == 0 && this.minute == 0 && this.second == 0) {
                this.dir = dir.getCanonicalDirection();
            } else {
                this.dir = dir;
        public Direction getDirection() {
            return dir;
        public int getMinute() {
            return minute;
        public int getDegree() {
            return degree;
        public int getSecond() {
            return second;
        public static GeoLine parseLine(String location) {
            * Matcher class will throw java.lang.NullPointerException if a null location
            *  is passed, null location validation is not needed.
            Matcher m = PATTERN.matcher(location);
            if(m.matches()) {
                int deg;
                int min;
                int second;
                Direction direction;
                deg = Integer.parseInt(m.group(1));
                min = Integer.parseInt(m.group(2));
                if (m.group(3) == null) {
                    second = 0;
                } else {
                    second = Integer.parseInt(m.group(3));
                direction = Direction.valueOf(m.group(4));
                return new GeoLine(deg, min, second, direction);
            } else {
                throw new IllegalArgumentException("Invalid location value. Expected format XXDXX'XX\"[NSEW] " + location);
        private void verifyMinute(int deg, int min, Direction direction) {
            /* This validation is to make sure that minute does not exceed 0 if maximum value for latitude == 90
            * or longitude == 180 is specified */
            int maxDeg = direction.isLatitude() ? 90 : 180;
            if(min < 0 || min > 59) {
               throw new NumberFormatException("Minutes is out of range. Value should be less than 60: " + min);
            if (deg == maxDeg && min > 0) {
                throw new NumberFormatException("Degree value " + deg + "D" + direction + " cannot have minute exceeding 0: " + min);
        private void verifyLongitudeLatitude(int valDeg, Direction valDir) {
               int max = valDir.isLatitude() ? 90 : 180;
               if(valDeg < 0 || valDeg > max) {
                    throw new NumberFormatException("Degree " + valDeg + valDir + " is invalid");
        public final boolean isLongitude() {
            return dir.isLongitude();
        public final boolean isLatitude() {
            return dir.isLatitude();
        @Override
        public final String toString(){
            if(minute < 10){
                return degree + "D0" + minute + dir;
            } else {
                return degree + "D" + minute + dir;
        @Override
        public boolean equals(Object obj) {
            if (obj instanceof GeoLine) {
                GeoLine other = (GeoLine) obj;          
                    return (this.degree == other.degree && this.minute == other.minute && this.second == other.second && this.dir == other.dir);
            return false;
        @Override
        public int hashCode() {
            int result = 17;
            result = result * 37 + degree;
            result = result * 37 + minute;
            result = result * 37 + second;
            result = result * 37 + dir.hashCode();
            return result;
    }Thank you again.

  • Mod_security: Access denied with code 405. Pattern match "!(GET|HEAD|POST)

    Hi all,
    After Cloning facing an issue
    mod_security: Access denied with code 405. Pattern match "!(GET|HEAD|POST)"
    and not able to get the login prompt
    EBS: 12.1.3
    DB:11G
    Please help as this is urgent.
    Regards,
    Raj.

    Hi Hussein/Srini,
    My OS details are as follows
    Source OS : OE Linux 5X
    Target : REHL
    DB : 11.2.0.3
    In my previous cloning the R12 login URL was not getting redirected to https from http. This backup was given by client last week and I completed the cloning and post cloning procedures without any error, but unable to login as the page is redirecting to https:/hostname:port/OA_HTML/AppsLogin.
    I have done the following so far, but the issue is not getting resolved.
    1) Generated JAR files using ADADMIN (Force)
    2) Compiled JSP
    3) Ran autoconfig multiple times without any error in both db and application tiers.
    4) DB alert log did not have any error.
    5) Executed relink all from APPL_TOP
    6) Able to launch http://XXXXXXXXX:XXXX/forms/frmservlet?
    Kindly help me out on this
    Regards

  • Who knows how to output some text once labview detects something I want using pattern matching(V​ision assistant)​?

    who knows how to output some text once labview detects something I want using pattern matching(Vision assistant)?
    The text is something like"Yes, this is a coin"
    Thanks!

    I attached a SubVI which I used to place an overlay next to a Pattern, found by a Pattern Match before:
    As you can see, you simply pass the image reference and the Array of Matches to the VI along with the String you want to have as an overlay next to the Match.
    I also modified your VI a bit, but didn't test it. I created an Array of clusters, each elment containing the template path along with the respective text.
    Please note that this is just a hint!
    Christian
    Attachments:
    suggestion.vi ‏146 KB
    Overlay_Txt.vi ‏24 KB

  • How to use AND,OR,NOT condition in Pattern Matching in java

    how to use AND,OR,NOT condition in Pattern Matching in java
    Please anyone give example..

    Stop asking these stupid vague questions and do some of your own research.
    Start here:
    http://www.regular-expressions.info/
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html

  • Pattern Matching and Vision Builder 6.0

    Hi,
    When I select a ROI from an image to generate a pattern matching, Builder
    saves it as a PNG file.
    If I open this pattern in other application (Paint Shop Pro 7) to modified
    it and save as a PNG file, after I can't open this file as a pattern into
    Builder, because it is considered as a not valid PNG file.
    I have tested this case in LabView 6.i and this problem doesn't appear.
    Any solution? Thanks.

    When the template is first saved in Vision Builder, pattern matching information is stored in the header of the PNG file. This information lets LabVIEW and Vision Builder know how the template was learned. Paint Shop Pro does not keep this information in the file whenever it is saved so Vision Builder will not recognize it as a valid pattern matching template.
    Jack Arnold
    Application Engineer
    National Instruments

  • Pattern matching problme - not getting desired result.

    Hi,
    According my program , If 'san' is in 'sangeetha', then it should display "hello".
    but I am getting only 'hi'
    Why ? any idea?
    <%@ page import="java.util.regex.Pattern"%>
    <%
    if(Pattern.matches("san", "sangeetha"))
    out.println("hello");
    else
    out.println("hi");
    %>
    Result : Hi

    sangee wrote:
    Hi,
    According my program , If 'san' is in 'sangeetha', then it should display "hello".No, that isn't what your patten say. You should read about regular expressions and learn how to use them, or switch to String.indexOf or contains.
    Kaj

  • Pattern matching for range of numbers

    I am facing problem in using a pattern like [200-300] to match any number in the range 200 and 300 inclusive. I wrote following code:
    public class RangeTest {
         public static void main(String[] args) {
              String pat = "[100-200]";
              String input = "100";
              // incpat.replace("[", "\\[");
              // incpat.replace("]", "\\]");                    
              System.out.println("Pattern" + pat);
              Pattern pattern = Pattern.compile(pat);
              Matcher matcher = pattern.matcher(input);
              if (matcher.matches()) {
                   System.out.println("EPC Matched:" + input + " and pattern:"              +matcher.pattern());                         
    }and tested it for different values of input , it's not working. I tried even giving escape characters for "[" and "]" (commented code). Can i use pattern matching in this case.
    Please help me.
    Regards,
    Prashanth

    I am facing problem in using a pattern like[200-300] to match any number in
    the range 200 and 300 inclusive.Try this one: "(2\d\d)|(300)".
    kind regards,
    Jos
    ps. Waiting for Sabre to jump in telling me that the
    parentheses aren't needed ;-)The parentheses aren't needed Jos! :-)

  • Vision assistant steps to be followed for pattern matching

    I am acquiring color images of hands movement using web camera of laptop.
    I want to process the acquired images to use for pattern matching.
    What are the steps to be followed to achieve the above mentioned task.

    In the following we proceed to function block search pattern extracted in the previous process (the parameters as rotation angle and minimum score is inserted into SETTINGS control), extract the output of the search function to get the position values indicators that will be displayed on the front panel)
    Atom
    Certified LabVIEW Associate Developer

  • Use of edge detection in pattern matching algorithm?

    Hello all,
                    I work for a group at Texas A&M University researching two-phase flow in reactors.  We have been using IMAQ Vision and had a question regarding the use of edge detection in the pattern matching algorithm.  I had seen the webcast entitled “Algorithms that Learn: The Sum and Substance of Pattern Matching and OCR” (http://zone.ni.com/wv/app/doc/p/id/wv-705) and in the webcast it was mentioned that the pattern matching algorithm uses edge detection to, (as best I can tell), reduce the candidate list further and to perform subpixel location calculations.  However, I was wondering if this edge detection process is still performed if we do not use the subpixel location calculation (i.e. if we uncheck the “Subpixel Accuracy” check box)?  Also, if edge detection is performed in the pattern matching algorithm is it consistent with the method described in Chapter 13 of the Vison Concepts Manual (“Geometric Matching”)?  Finally, if edge detection is performed in a manner consistent with Chapter 13 of the manual, how does the geometric matching correlation number affect the correlation calculation that was performed in the previous steps?  Are they simply multiplied together?
    Many thanks!
      -Aaron

    Jeff,
    We are using Imaq Vision Builder 4, with the included pattern matching that can be accessed via the menus (i.e. we haven't created a custom VI or anything.)  We are using the software to locate bubbles during boiling experiments and want a deeper understanding of what is going on "behind the scenes" of the algorithm, as we may have to explain how it works later.  We have been able to determine most of what we need from the webcast I had previously mentioned, except for the use of edge detection in the pattern matching algorithm.
    At the scales involved in our experiments, subpixel accuracy is really not needed and therefore we do not use it.  If edge detection is used in the pattern matching algorithm only to determine location with subpixel accuracy, then we do not really need to know how it works because we do not use that calculation.  Inversely, of course, if edge detection is used during pattern matching even without enabling subpixel accuracy, then we would like to have a fairly good understanding of the process.
    I've read most of the section on geometric matching in the Vision Concepts Manual and wondered if the process described there for edge detection (or feature matching) was also used in the basic pattern matching algorithm?
    To summarize, if edge detection is not used in the basic pattern matching algorithm without subpixel accuracy, then that is all I need to know.  If edge detection is used for pattern matching even without using the subpixel accuracy calculation, then we would like to learn more about how exactly it is used in the pattern matching algorithm.
    We would really appreciate any help you could give us... we've been digging around on the NI website for a couple of weeks now trying to fit together all the pieces of the pattern matching puzzle.
    Many thanks!
        Aaron

  • Pattern matching in String

    Hi,
    I want to do pattern matching using String. Here is my requirement.
    String file_name = (String)hash.get("DOCNAME"));
    file_name = file_name.replace("'","285745@");
    So, whereever I have '(apostrophe) I will replace it with pattern "285745@" and then at another jsp where I get this request parameter I do reverse as follows:
    String docname = (String)request.getParameter("doc_name").replace("285745@","'");
    Now I know replace function is not going to do this. It is just a indicative, for you to know what I want to achieve. which other java function / method i can implement to get the desired result.
    thanks,
    pp

    String file_name = (String)hash.get("DOCNAME"));
    file_name = file_name.replace("'","285745@");The problem here is that String.replace() operates only on char arguments, you cannot replace entire substrings with it.
    The String.replaceAll() method, on the other hand, operates on regular expressions. In many common cases (those in which the substring you want to find contains no characters with special meaning to the regular expression processor) you can use it exactly as you would String.replace() except that it operates on substrings.
    But regular expressions are much more powerful than that. The javadoc for the "Pattern" class has some information on how to use them. There is also a tutorial at http://java.sun.com/docs/books/tutorial/extra/regex/intro.html which you might find helpful.
    In the 1.4 edition of Java there is no longer any need to screw around with while loops and StringBuffers. Nearly any text processing operation can be done with regular expressions.

Maybe you are looking for

  • How to Edit the Title (file name) on forms 10g Screen.

    Hi , How can one edit the Title ,and <(file name)> on forms 10g Screen .... I tried editing through the forms module preperty palette , but could n't change the Title, or file name on forms menu screen ... I guess , the entries are made through some

  • Need help with G5 connected to AirPortExpress!

    I simply can't find the source of this problem, and any help is very welcome: When my G5 2x2,5GHz and OS 10.4.8 is connected to my AirPort Express network, the connection suddenly becomes very slow and it takes forever to download a simple page. The

  • Brand new Macbook pro login problem after migration

    I just bought a new Mac Book Pro, and decided to migrate my documents and applications too it - but did not tick network passwords. On finishing the migration it is asking me for the login to my account. Actually I bought this for a friend, and was f

  • How to make linesize for autotrace be larger than 80?

    Is it possible to make that the linesize of the output in sqlplus to be larger than 80? I have my linesize = 150 but the output of the autotrace is wrapped and it is quite difficult to see.

  • Creating 2 header in ALV (Urgent!)

    Hello... i have aproblem right now. i want to create report using ALV grid and i'm using OO method, the problem is, i want to create 2 header in the same screen, for example [header1]                              [header2] name place