Unique regular expression to check if a string contains letters and numbers

Hi all,
How can I verify if a string contains numbers AND letters using a regular expression only?
I can do that with using 3 different expressions ([0-9],[a-z],[A-Z]) but is there a unique regular expression to do that?
Thanks all

Darin.K wrote:
Missed the requirements:
single regex:
^([[:alpha:]]+[[:digit:]]+|[[:digit:]]+[[:alpha:]])[[:alnum:]]*$
You either have 1 or more digits followed by 1 or more letters or 1 or more letters followed by 1 or more digits. Once that is out of the way, the rest of the string must be all alphanumerics.  The ^ and $ make sure the whole string is included in the match.
(I have not tested this at all, just typed it up hopefully I got all the brackets in the right place).
I think you just made my point.  TWICE.  While the lex class would be much more readable as a ring.... I know all my brackets are in the correct places and don't need to hope.
Jeff

Similar Messages

  • Regular expression to check the sequence of strings

    HI,
    I am validating an EDI document like as follows
    ISA*XX*XXXXXXXXXXXXXXX*XX*XXXXXXXXXXXXXXX*030130*0912*~IEA*1*000005900~
    I need to create a regular expression which checks ISA should always occur before IEA.
    Please help me if you have any hints.
    Thanks.

    Thanks.I had taken that into consideration.
    But using regular expression I could say
    ISA* only once
    IEA* only once
    And
    ISA before IEA
    Any hints how to specify "before"/sequence using Regular expression ?
    I agree sometime using basic String operation we can do this.

  • How to specify ");" as a regular expression in split method of String class

    How to specify ");" as a regular expression in split method of String class using delimeters?

    Sorry, you can't specify that by using delimiters. Mostly because this requirement makes no sense.
    Do you rather need "\\);"?

  • Regular Expression to check for some of the special characters

    Can someone please provide me a RegularExpression to check if a string contains any of the speical characters i.e. *!@#$%^&*()_+ []{}:;',./<>?~`*
    Thanks
    Edited by: whitesox12 on Apr 3, 2008 9:46 PM

    [*!@#$%\^&()_+\[\]{}:;',./?~`]In a Java string literal, a backslash should be written as two consecutive backslashes.

  • Check if a string contains another string

    can anybody help?
    String st="DC";
    how can i check if another string contains "DC" or not?

    How bout
    if(someString.indexOf(st) != -1) {
         //someString contains st at some point
    }

  • Is it possible to search for strings containing spaces and special characters?

    In our RoboHelp project, there are figures with text labels such as Figure 1, Figure 3-2, etc.
    When I search for "Figure 3" I get all pages containing "Figure" and "3", even if I surround it in quotes.  Similarly, searching for "3-2" treats the '-' character as a space and searches for all pages containing '3' or '2'.
    Is there a way to search for strings containing spaces and special characters?

    In that case I think the answer is no if you are using the standard search engine. However I believe that Zoom Search does allow this type of searching. Check out this link for further information.
    http://www.grainge.org/pages/authoring/zoomsearch/zoomsearch.htm
      The RoboColum(n)
      @robocolumn
      Colum McAndrew

  • Is there a way to differentiate string containing characters vs. numbers?

    Hello, I am creating an application to read data from a serial port device. The problem is that the device, on startup, outputs a block of text containing characters describing the device. Shortly after, it outputs a command prompt "Command:" It is at this point that I want my VI to input the command to begin taking measurements.
    I was looking at the VISA Wait on Event and it looks like that could be used to wait for the device to output a "Serial Character" but there is no differentiation between letters and numbers that I can tell.
    If the device is outputting numbers in the read string, of course, I do not need to input the command to begin taking measurements again, that will only probably confuse the device. In that case, I would like my VI to continue taking measurements with VISA Read.
    The reason for this is that when I run the application, the device may have already been turned on. Sending that command to the device using VISA Write is unnecessary at that point.
    Any advice would be appreciated. Thanks.
    Solved!
    Go to Solution.

    That makes it alot easier.  In that case this will do the trick.  You'll notice that the bottom case does not match even though it has valid vaules inside of it.  The only thing that will match is if the entire string is of the form XX.XXXX.  By the way, since we are only matching numbers now, you can remove the "ignore case" boolean as it no longer matters.
    Message Edited by SiegeX on 11-24-2008 03:58 PM
    Attachments:
    regex.png ‏4 KB

  • Regular expression - get longest number from string

    I believe it is easy one but I can't get it.Lets say I have a string 'A1_1000' I want to substract the 1000 using regular expression. When I feed Match regular expression I get '1' which is not the longest number. I know other ways of doing that but I want clean solution in one step. Does anybody knows the right regular expression to accomplish that? Thanks!
    LV 2011, Win7
    Solved!
    Go to Solution.

    ceties wrote:
    This is the best solution I was able to come with. I am just wondering if there is "smoother way" without the cycle.
    Since multiple checks are required I would tend to beieve that we do have to loop through the possibilities. in this example
    I start check at offset "0" into the string for a number. Provided i find a number I check if it is longer that any previous number I found and if so save the new longer number in the shift register.
    Have fun!
    Ben
    Message Edited by Ben on 04-15-2009 09:23 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Find_Longest.PNG ‏33 KB

  • OR ('|') in regular expressions (e.g. split a String into lines)

    Which match gets used when you use OR ('|') to specify multiple possible matches in a regex, and there are multiple matches among the supplied patterns? The first one (in the order written) which matches? Or the one which matches the most characters?
    To make this concrete, suppose that you want to split a String into lines, where the line delimiters are the same as the [line terminators used by Java regex|http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#lt] :
         A newline (line feed) character ('\n'),
         A carriage-return character followed immediately by a newline character ("\r\n"),
         A standalone carriage-return character ('\r'),
         A next-line character ('\u0085'),
         A line-separator character ('\u2028'), or
         A paragraph-separator character ('\u2029)
    This problem has [been considered before|http://forums.sun.com/thread.jspa?forumID=4&threadID=464846] .
    If we ignore the idiotic microsoft two char \r\n sequence, then no problem; the Java code would be:
    String[] lines = s.split("[\\n\\r\\u0085\\u2028\\u2029]");How do we add support for \r\n? If we try
    String[] lines = s.split("[\\n\\r\\u0085\\u2028\\u2029]|\\r\\n");which pattern of the compound (OR) regex gets used if both match? The
    [\\n\\r\\u0085\\u2028\\u2029]or the
    \\r\\n?
    For instance, if the above code is called when
    s = "a\r\nb";and if the first pattern
    [\\n\\r\\u0085\\u2028\\u2029]is used for the match when the \r is encountered, then the tokens will be
    "a", "", "b"
    because there is an empty String between the \r and following \n. On the other hand, if the rule is use the pattern which matches the most characters, then the
    \\r\\n
    pattern will match that entire \r\n and the tokens will be
    "a", "b"
    which is what you want.
    On my particular box, using jdk 1.6.0_17, if I run this code
    String s = "a\r\nb";
    String[] lines = s.split("[\\n\\r\\u0085\\u2028\\u2029]|\\r\\n");
    System.out.print(lines.length + " lines: ");
    for (String line : lines) System.out.print(" \"" + line + "\"");
    System.out.println();
    if (true) return;the answer that I get is
    3 lines:  "a" "" "b"So it seems like the first listed pattern is used, if it matches.
    Therefore, to get the desired behavior, it seems like I should use
    "\\r\\n|[\\n\\r\\u0085\\u2028\\u2029]"instead as the pattern, since that will ensure that the 2 char sequence is first tried for matches. Indeed, if change the above code to use this pattern, it generates the desired output
    2 lines:  "a" "b"But what has me worried is that I cannot find any documentation concerning this "first pattern of an OR" rule. This means that maybe the Java regex engine could change in the future, which is worrisome.
    The only bulletproof way that I know of to do line splitting is the complicated regex
    "(?:(?<=\\r)\\n)" + "|" + "(?:\\r(?!\\n))" + "|" + "(?:\\r\\n)" + "|" + "\\u0085" + "|" + "\\u2028" + "|" + "\\u2029"Here, I use negative lookbehind and lookahead in the first two patterns to guarantee that they never match on the end or start of a \r\n, but only on isolated \n and \r chars. Thus, no matter which order the patterns above are applied by the regex engine, it will work correctly. I also used non-capturing groups
    (?:X)
    to avoid memory wastage (since I am only interested in grouping, and not capturing).
    Is the above complicated regex the only reliable way to do line splitting?

    bbatman wrote:
    Which match gets used when you use OR ('|') to specify multiple possible matches in a regex, and there are multiple matches among the supplied patterns? The first one (in the order written) which matches? Or the one which matches the most characters?
    The longest match wins, normally. Except for alternation (or) as can be read from the innocent sentence
    The Pattern engine performs traditional NFA-based matching with ordered alternation as occurs in Perl 5.
    in the javadocs. More information can be found in Friedl's book, the relevant page of which google books shows at
    [http://books.google.de/books?id=GX3w_18-JegC&pg=PA175&lpg=PA175&dq=regular+expression+%22ordered+alternation%22&source=bl&ots=PHqgNmlnM-&sig=OcDjANZKl0VpJY0igVxkQ3LXplg&hl=de&ei=Dcg7S43NIcSi_AbX-83EDQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CA0Q6AEwAA#v=onepage&q=&f=false|http://books.google.de/books?id=GX3w_18-JegC&pg=PA175&lpg=PA175&dq=regular+expression+%22ordered+alternation%22&source=bl&ots=PHqgNmlnM-&sig=OcDjANZKl0VpJY0igVxkQ3LXplg&hl=de&ei=Dcg7S43NIcSi_AbX-83EDQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CA0Q6AEwAA#v=onepage&q=&f=false]
    If this link does not survive, search google for
    regular expression "ordered alternation"
    My first hit went right into Friedl's book.
    Harald.

  • Using Regular Expressions to replace Quotes in Strings

    I am writing a program that generates Java files and there are Strings that are used that contain Quotes. I want to use regular expressions to replace " with \" when it is written to the file. The code I was trying to use was:
    String temp = "\"Hello\" i am a \"variable\"";
    temp = temp.replaceAll("\"","\\\\\"");
    however, this does not work and when i print out the code to the file the resulting code appears as:
    String someVar = ""Hello" i am a "variable"";
    and not as:
    String someVar = "\"Hello\" i am a \"variable\"";
    I am assumming my regular expression is wrong. If it is, could someone explain to me how to fix it so that it will work?
    Thanks in advance.

    Thanks, appearently I'm just doing something weird that I just need to look at a little bit harder.

  • Regular expression to check a value if it contains a specific word.

    Hi All,
    How can i check if a certain word exists in a value in regular expression ?
    I have an attribute called Race. Race can contain the following:
    White, Non-Hispanic
    Black, Non-Hispanic
    White, Non Hispanic
    Black, Non Hispanic
    White, NonHispanic
    Non-Hispanic, white
    Non Hispanic - black
    What i want is to check if my value contains the word "NON" (NON can be at the beginning, middle or end), if it does, parse it and return it.
    This is what I have, however I want to make sure it covers all cases and not missing anything else
    select REGEXP_SUBSTR(UPPER(trim('Black, Non-Hispanic')), '[NON]+') from dual;Thanks in advance.

    Rooney wrote:
    Could you please explain what are the 2 ones's for ?The two 1 are not really needed for this. It is just taht the syntax requires those parameters when I add the fifth parameter.
    http://docs.oracle.com/cd/E14072_01/server.112/e10592/functions148.htm
    First 1 is where the search starts (same as in substr('Abc',1))
    Second 1 is the number of occurences. Here meaning return the first occurence that was found. Replace it with 2 in my next example to see a (very slight) difference.
    Also 'NON' alone will not cover all cases ?But you don't have non alone. You have regexp with non + upper. The 'i' replaces the upper. Also the output is slightly different. the 'i' version will return the same capitalization as it was found in the original. It depends a little what you want to achieve. And of cause INSTR will give the same info as your version. if the result is > 0 it means NON was found.
    with testdata as (select 'White,Non-Hispanic' str from dual union all
                      select 'Non-White,nOn-Hispanic' str from dual union all
                      select 'White,Hispanic' str from dual
    /* end of test data creation */
    select str,
          REGEXP_SUBSTR(UPPER(TRIM(str)), 'NON') regexp1,
          REGEXP_SUBSTR(str, 'NON',1,1,'i') regexp2,
          instr(upper(str),'NON') instr
    from testdata;
    STR                    REGEXP1                REGEXP2                INSTR
    White,Non-Hispanic     NON                    Non                        7
    Non-White,Non-Hispanic NON                    Non                        1
    White,Hispanic                                                           0

  • A regular expression to detect a blank string...

    Anyone know how to write a regular expression that will detect a blank string?
    I.e., in a webservice xsd I'm adding a restriction to stop the user specifying a blank string for an element in the webservice operation call.
    But I can't figure out a regular expression that will detect an entirely blank string but that will on the other hand allow the string to contain blank spaces in the text.
    So the restriction should not allow "" or " " to be specified but will allow "Joe Bloggs" to be specified.
    I tried [^ ]* but this wont allow "Joe Bloggs" to pass.
    Any ideas?
    Thanks,
    Ruairi.

    Hi ruairiw,
    there is a shortcut for the set of whitespace chars in Java. It is the Expression *\s* which is equal to *[ \t\n\f\r\u000b]*.
    With this expression you can test whether a String consists only of whitespace chars.
    Expamle:
    String regex = "\\s*"; // the slash needs to be escaped
    // same as String regex = "[ \t\n\f\r\u000b]";
    System.out.println("".matches(regex)); // true
    System.out.println("   ".matches(regex)); // true
    System.out.println("  \r\n\t ".matches(regex)); // true
    System.out.println("\n\nTom".matches(regex)); // false
    System.out.println("   Tom Smith".matches(regex)); // falseBesh Wishes
    esprimo

  • Regular Expression to Check number with at least one decimal point

    Hi,
    I would like to use the REGEX_LIKE to check a number with up to two digits and at least one decimal point:
    Ex.
    10.1
    1.1
    1
    12
    This is what I have so far. Any help would be appreciated. Thanks.
    if regexp_like(v_expr, '^(\d{0,2})+(\.[0-9]{1})?$') t

    Hi,
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    SammyStyles wrote:
    Hi,
    I would like to use the REGEX_LIKE to check a number with up to two digits and at least one decimal point:
    Ex.
    10.1
    1.1
    1
    12
    This is what I have so far. Any help would be appreciated. Thanks.
    if regexp_like(v_expr, '^(\d{0,2})+(\.[0-9]{1})?$') t
    Do you really mean "up to two digits", that is, 3 or more digits is unacceptable?  What if there are 0 digits?  (0 is less than 2.)
    Do you really mean "at least one decimal point", that is, 2, 3, 4 or more decimal points are okay?  Include some examples when you post the sample data and results.
    It might be more efficient without regular expressions.  For example
    WHERE   TRANSLATE ( str              -- nothing except digits and dots
                      , 'A.0123456789'
                      , 'A'
                      )   IS NULL
    AND     str           LIKE '%.%'     -- at least 1 dot
    AND     LENGTH ( REPLACE ( str       -- up to 2 digits
                    )     <= 2

  • 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"
    }

  • How check if a string contains a generic character?

    I want know how i can check if this string
    String mio= new String("Error 101");contains this substring
    1xxwhere "xx" are two generic characters that follow "1".
    Thanks
    Message was edited by:
    PremierITA

    Use a regular expression.Pattern threeDigitNumberThatStartsWith1 = Pattern.compile(".*1\\d\\d.*");
    Matcher matcher = pattern.matcher(mio);
    if(matcher.matches()) {
      // found it!
    else {
      // didn't find it
    }More about pattern matching here: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

Maybe you are looking for

  • Office Web Apps is not working

       Hi,      We have tried to deploy Office Web Apps Server but, after a number of tests, we haven't been able to view PowerPoint presentations. We tested "everything" but it didn't work.      Finally, to simplify and focus the problem, we just deploy

  • My Iphone 6 plus Screen cracked

    i slightly cracked my T-Mobile iphone 6 plus screen in the bottom an i wanna know if apple fixes that proplem without me having to pay T-mobile 150$ for another one 6plus please help

  • How to create transactoin code for a predefined variant?

    Hi,  I have created one variant for a custom report.How to create transaction code for the report with that variant?

  • Antenna type in WCS / WLC

    Hello, I am still somewhat new to the wireless side and I saw something today while trying to troubleshoot a wireless issue we were having that I have not heard or read about from my CCNA Wireless studies. I noticed that the antenna types our WCS is

  • Macbook Pro4,1 can't find 3 finger gestures in SysPref

    I have a Macbook Pro4,1 (early 2008) and I can't find options to turn on 3 finger swiping. From what i can find, my MBP should have it.  10.7.4. 2.4 GHz Intel Core 2 Duo http://support.apple.com/kb/HT1115