Regular Expressions to Omit Characters

I am new to Java. I am trying to use regular expressions to omit a pattern. The construct [^abc] can be used to omit a or b or c, but how can I omit the string abc from a regular expression? Many thanks.

Why not use the regular expression "abc" and see if it doesn't match? Or even use this:
boolean matches = (targetString.indexOf("abc") == -1); // == -1 means "not found", so matches become true if abc is not in targetString
if (matches) System.out.println("Yay, no abc in " + targetString + "!");
else System.out.println("Eek, get that abc out of my sight!");

Similar Messages

  • String Regular Expression for uncommon characters

    Hi,
    I am trying to get text out of HTML file for which I am using EditorKit and Document classes. After I obtain the text, the text (String) contains some characters like �. This character looks like a with French style acute accent . My problem is how to use regular expression to find and replace (replaceAll method) these unwanted characters.
    Is there a regular expression pattern for such characters?
    Thanks!
    Rahul.

    hrm I would recommend looking at the specific patterns,
    a simplified site would be here http://www.p3m.org/wiki?regex
    as a refernce . If you dont know regular expression, use
    http://www.perl.com/doc/manual/html/pod/perlre.html
    The only way I could think of constructing the regex is to use the \s and add the characters you want in that regex :s you could look into regex look ahead and look behind methods...

  • Regular Expression Exclude Certain Characters

    I am building this with Apex 3.2
    I have a validation on a page item of type regular expression
    Validation Expression 1 :   P13_TARGET_BMI
    Validation Expression 2:    ^[[:alnum:]-]*$
    This allows all characters, number and the - symbol
    Now I need to exclude certain alpha characters, ie German letters Ä Ü Ö
    and spaces if possible
    Basically if the user types in Ä, Ü, Ö, the validation should fail
    Cheers
    Gus

    Hi, Gus,
    The most efficient thing would be to list all the acceptable characters instead of using [:alnum:].
    REGEXP_LIKE ( str
                , '^[a-z0-9A-Záéíóúæ... -]+$'
    If you can't do that, then use a separate test to check for the exceptional alphabetic characters
         REGEXP_LIKE ( str
                     , '^[[:alnum:] -]+$'
    AND  str = TRANSLATE ( str
                         , 'xÄÜÖ'
                         ,'x'
    You can use regular expressions for the Ä Ü Ö testing, if you want to.
    There's nothing tricky about spaces; by default, they have no special meaning in regular expressions, and they never have any special meaning inside square brackets.

  • Using Regular Expressions To Remove Characters JDK 1.4

    I want to write a regular expression to remove all commas in a string of text.
    string is:
    1,000
    or 1,000,000
    I want it to return 1000 and 1000000.
    I have tried some but I am just starting with Regular Expressions.
    Please Help!

    Try this tutorial: Linux : Education : Tutorials
    Using regular expressions
    David Mertz
    President, Gnosis Software, Inc.
    September 2000
    http://www-105.ibm.com/developerworks/education.nsf/linux-onlinecourse-bytitle/6C2B4863702F592B8625696200589C5B?OpenDocument

  • 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.

  • Regulare Expressions - Uses of logical operators

    I need to make use of logical operators within a regulare expression. (greater than, equal, etc.)
    It seems to me that java.util.regex.Pattern does not support that kind of expression. First of all: Is this true (If I am wrong with my assumption, how would the expression look like). Secondly: Which library does support this expression?
    Thanks in advance!

    Regular expressions deal with characters. In that context all characters are 'equal'. You better explain your question a helluva lot better than that.

  • Regular Expression for /, \, #, -, & ‘

    Hi,
    Can anybody tell me the regular expression for provided characters.
    Code is preferable.
    Thanks in advance.

    "[-/\\\\#&']"

  • Regular expression help please. (extractin​g a string subset between two markers)

    I haven't used regular expressions before, and I'm having trouble finding a regular expression to extract a string subset between two markers.
    The string;
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    ERRORS 6
    Info I want line 1
    Info I want line 2
    Info I want line 3
    Info I want line 4
    Info I want line 5
    Info I want line 6
    END_ERRORS
    From the string above (this is read from a text file) I'm trying to extract the string subset between ERRORS 6 and END_ERRORS. The number of errors (6 in this case) can be any number 1 through 32, and the number of lines I want to extract will correspond with this number. I can supply this number from a calling VI if necessary.
    My current solution, which works but is not very elegant;
    (1) uses Match Regular Expression to the return the string after matching ERRORS 6
    (2) uses Match Regular Expression returning all characters before match END_ERRORS of the string returned by (1)
    Is there a way this can be accomplished using 1 Match Regular Expression? If so could anyone suggest how, together with an explanation of how the regular expression given works.
    Many thanks
    Alan
    Solved!
    Go to Solution.

    I used a character class to catch any word or whitespace characters.  Putting this inside parentheses makes a submatch that you can get by expanding the Match Regular Expression node.  The \d finds digits and the two *s repeat the previous term.  So, \d* will find the '6', as well as '123456'.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • How to use special characters in regular expression

    HI all, I am new to regular expression.
    Can any one please tell me the regular expression for characters which are used in regular expression like " [({. tetc.Is there any particular expression to prefix before using these characters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Expression:
    < td .*? bgcolor = \" ( [^ \" ] +) \" \\s* .*? > ( .+? ) </td>
    It will search for expression starting with <td ,
    .*? means any characters zero or more than one,
    then it will find bgcolor = , then literal \"... \(any char) is that specific char
    [ ^ \" ] any character but not literal \",this means there has to be something between ".... " if empty then wont match ,+ is 1 or more times
    Then again literal \ " , after that \\s* means zero or more num of spaces,
    then again , .*? means any characters zero or more than one,
    it will search for literal > , again any chars . * ?
    Finally </td> will be searched.....!!
    So all expressions having this particular structure will be
    matched.
    Output :
    <td align="left" valign="top" bgcolor="ffffff" width="177">bla bla bla</td>

  • Regular Expressions and Double Byte Characters ?

    Is it possible to use Java Regular Expressions to parse
    a file that will contain double byte characters ?
    For example, I want a regular expression to match the following line
    tag="double byte stuff" id="double byte stuff"

    The comments on the bytes/strings were helpful. Thanks.
    But I'm still confused as to what matching pattern could be used.
    For example a pattern like:
    [A-Za-z]
    I assume would not match any double byte characters.
    I also assume the following won't work either:
    [\\p{Alpah}]
    because it is posix - US-ASCII only.
    So how do you say "match the tag, then take any characters,
    double byte, ascii, whatever, then match the text tag - per the
    original example ?

  • Regular expressions-how to replace [ and ] characters from a string

    Hi,
    my input String is "sdf938 [98033]". Now from this given string, i would like to replace the characters occurring within square brackets to empty string, including the square brackets too.
    my output String needs to be "sdf938" in this case.. How should I do it using regular expressions? I tried several possible combinations but didn't get the expected results.

    "\\s*\\[[^\\]]+\\]"

  • Converting String Characters into Regular Expression Automatically?

    Hi guys.... is there any program or sample coding which is available to convert string characters into regular expression automatically when the program is run?
    Example:
    String Character Input: fnffffffffffnnnnnnnnnffffffnnfnnnnnnnnnfnnfnfnfffnfnfnfnfnfnnnnd
    When the program runs, it automatically convert into this :
    Regular Expression Output: f*d

    hey guys.... i am sorry for not providing all the information that you guys need as i was rushing off to urgent meeting... for my string characters i only have a to n.. all these characters are collected from sensors and stored inside database... from many demos i have done... i found out that every demo has different strings of characters collected and these string of characters will not match with the regular expressions that i had created due to several unwanted inputs and stuff... i have a lot of different types of plan activities and therefore a lot of regular expressions.... if i put [a-z|0-9]*... it will capture all characters but in the same time it will be showing 1 plan only.... therefore, i am finding ways to get the strings i collected and let it form into regular expression by themselves in the program so that it will appear as different plans as output with comparing with the regular expression that i had created.... is there any way to do so?
    please post again if there is any questions u are still not familiar with... thank you...

  • Changeparticular characters in a string by using regular expressions ...

    Hello Everyone,
    I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
    My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
    Is it possible by using regular expressions in oracle ?
    Can you give me some clues ?
    Thank you

    SSU wrote:
    Hello Everyone,
    I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
    My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
    Is it possible by using regular expressions in oracle ?
    Can you give me some clues ?
    Thank you
    SQL> SELECT
      2  regexp_replace('sdfsdf Sdfdfs Sdfd','s|S','X') from dual;
    REGEXP_REPLACE('SD
    XdfXdf XdfdfX XdfdRegards,
    Achyut

  • Regular Expression for finding Latin characters

    i have a table "t" with values in column "text" like
    "Āniki"
    "Ąvatar"
    How can I find them using a regular expression?
    The real goal is to replace them with their ASCII equivalent.
    Ā = A
    Č = C
    Ĥ = H
    etc....

    You can set any range in the ascii table by using the expression 'X-Y' in the pattern. It works for symbols too, but you need to find out whether the desired characters you're interested actually form a contiguous range.
    You can run the below query to check the ascii table:
    SELECT LEVEL ascii_val, chr(LEVEL) chr_column FROM dual CONNECT BY LEVEL < 256;Then you can pick and choose your ranges and verify them as in the following query:
    WITH t AS
    (SELECT LEVEL ascii_val, chr(LEVEL) chr_column FROM dual CONNECT BY LEVEL < 256)
    SELECT ascii_val, chr_column FROM t WHERE regexp_like(chr_column, '[^A-Za-z0-9!-/]');In the example above I chose a range from the ascii 33 ('!') to 47 ('/'), described by the portion '!-/' in the pattern.
    To add another range just concatenate it after the slash symbol.
    Additionally, for example, if you want to add a range including the symbols:
    ASCII CHR
    58    :
    59    ;
    60    <
    61    =
    62    >
    63    ?You can set it up like this instead if you feel it's more easily readable:
    WITH t AS
    (SELECT LEVEL ascii_val, chr(LEVEL) chr_column FROM dual CONNECT BY LEVEL < 256)
    SELECT ascii_val, chr_column
      FROM t
    WHERE regexp_like(chr_column, '[^A-Za-z0-9' ||
                                   chr(33) || '-' || chr(47) ||
                                   chr(58) || '-' || chr(63) ||
                                   ']');You need to test this though, as the docs state the behaviour may vary depending on your NLS_SORT settings, by using linguistic ranges rather than byte values. For my settings it seems to work, not sure about everywhere else.
    Note: In the POSIX standard, a range includes all collation elements between the start and end of the range in the linguistic definition of the current locale. Thus, ranges are linguistic rather than byte values ranges; the semantics of the range expression are independent of character set. In Oracle Database, the linguistic range is determined by the NLS_SORT initialization parameter.http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_regexp.htm
    and
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10729/ch5lingsort.htm
    You can check your NLS_SORT by querying the userenv:
    SQL> select sys_context('USERENV', 'NLS_SORT') from dual;
    SYS_CONTEXT('USERENV','NLS_SOR
    WEST_EUROPEAN
    SQL> If it returns BINARY you need not worry about it.
    Otherwise you can check the particular sorting your NLS_SORT will use here:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10729/applocaledata.htm#NLSPG593
    Usually symbols are not affected by it as you can see there (my case too for the "west_european" value), but other elements in a string can be affected.
    Regards,
    Sitja.
    Edited by: fsitja on Mar 18, 2010 1:51 PM

  • Regular expression - escape characters

    Hi. Is there an escape character for "?", "[", "]", "{", "}" for regular expression? I tried to do the following: "[^[]?{}]*" (the string cannot contain a question mark, left or right bracket, or left or right curly brace). However, I get an error stating unexpected character.
    thanks,
    Paul.

    Hi. Is there an escape character for "?", "[", "]",
    "{", "}" for regular expression? I tried to do the
    following: "[^[]?{}]*" (the string cannot contain a
    question mark, left or right bracket, or left or right
    curly brace). However, I get an error stating
    unexpected character.
    You should only have to escape the characters that cause a problem in the character class, rather than everything so the following should work.
    "[^\\[\\]?{}]*"

Maybe you are looking for