Write REGEX for a string pattern

Hi All,
I am new to using regular expression and writing the patterns, I am looking to write a pattern for below formats and do a FIND REGEX:
A123456-01-123456789-123   and A123456-01-123456789-ABC
DATA: regex TYPE REF TO cl_abap_regex,
      res   TYPE        match_result_tab,
      text  TYPE        string.
CREATE OBJECT regex
    EXPORTING pattern      = '\(.\)\1'
              simple_regex = 'X'
FIND ALL OCCURRENCES OF REGEX regex IN text RESULTS res.
could you help me write the pattern to check if user has entered string in formats A123456-01-123456789-123   and A123456-01-123456789-ABC
Thank you
Depp

Hi Manish,
First of all sorry for getting back so late..was stuck with project delivery...and Thank you for your solution. Only one scenario failed i.e., I didn't mention that the value 01 in the examples, is constant in strings A123456-01-123456789-123   and A123456-01-123456789-ABC.
which means it has to be always 01 any other value than 01 the sy-subrc should not be zero.
I will also be thankful if you could share me the document(s) which help us write the above patterns( '^\w\d{6}-\d{2}-\d{9}-\d{3}$' ; '^\w\d{6}-\d{2}-\d{9}-\w{3}$' ).
In the meanwhile I will also do some R&D with your reply to solve the failed scenario.
Regards,
Depp

Similar Messages

  • XML Schemas: Regex for empty string?

    Hi Folks,
    It appears that the new Oracle schema processor has a bug in processing regular expressions.
    Example. Create a regular expression which allows a string of characters 5-10 characters in length, or empty.
    Here's the regex:
    [a-zA-Z]{5-10}|()
    When I use this in a pattern facet and in my instance document create an empty element for this type it gives me an error message (sorry, I don't recall the exact message).
    /Roger

    Roger, empty expr is illegal in current implementation. We will add this support in next release.
    Thanks,
    Oracle XML develop team

  • Regex Pattern For this String ":=)"

    Hello All
    True, this isn't the place to ask this but here it is anyway, if you can help please do.
    Can anybody tell me the regex pattern for this String:
    ":=)"
    Thanks
    John

    Yep, cheers it's ":=\\)"
    public class Test {
         public static void main( String args[] ) {
              String s = "one:=)two:=)three:=)four";
              String ss[] = s.split( ":=\\)" );
              for( int i=0; i<ss.length; i++ )
                   System.out.println( "ss["+i+"] = {" + ss[i] + "}" );
    }resulting in:
    ss[0] = {one}
    ss[1] = {two}
    ss[2] = {three}
    ss[3] = {four}

  • How to search for a particular pattern in a string

    Hi,

    Hi ,
    How to search for a particular pattern in a string?
    I heard about java.util.regex; and used it in my jsp program.
    Program I used:
    <% page import="java.util.regex"%>
    <% boolean b=Pattern.matches("hello world","hello");
    out.println(b);%>
    I run this program using netbeans and am getting the following error message.
    "Cannot find the symbol : class regex"
    "Cannot find the symbol : variable Pattern "
    How to correct the error?

  • Regex for url pattern validation

    Hi,
    I am trying to find a regex for Url pattern validation that is not too restrictive.
    Please let me know, if anyone is using a pattern for their applications.
    Thanks
    Mayank Sharma

    are you talking about xml schema restriction?
    <xs:element name="url">
      <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="(https?://)?[-\w.]+(:\d{2,5})?(/([\w/_.]*)?)?" />
       </xs:restriction>
      </xs:simpleType>
    </xs:element>

  • How do I write a macro that would look for a string in an entire column

    how do I write a macro that would look for a string in an entire column. If the string is found, it will copy that entire row to a new sheet in that same file?
    I want to look in an entire column lets say "C" for different strings of numbers like 246, 88, 68, 82246 etc... and copy them to a new sheet
    Thanks

    Hello Larbec,
    Try this:
    Option Explicit
    Sub test()
        Dim myNumber As Integer
        Dim myNumbers() As Integer
        Dim i As Integer
        Dim c As Range
        Dim firstAddress As Variant
        myNumbers = Array(246, 88, 68, 82246)
        For i = 0 To UBound(myNumbers)
            myNumber = myNumbers(i)
            With ActiveSheet.Range("C:C")
                Set c = .Find(myNumber, LookIn:=xlValues)
                If Not c Is Nothing Then
                    firstAddress = c.Address
                    Do
        ' Copy c.value to OtherSheet here !!!!
                        Set c = .FindNext(c)
                    Loop While Not c Is Nothing And c.Address <> firstAddress
                End If
            End With
        Next i
    End Sub
    Best regards George

  • Match pattern for multiple strings in labVIEW

    I want to include multiple strings for matching in the regular expression for pattern matching.I tried using the or option and (|)
    eg:cat|dog|mouse
    If the string contains any of these it should show a match.
    Is it possible in labview or do i need to use multiple patch mattern functions to achieve this?

    Match Regular Expression function will do.
    You can search for multiple strings using | operator. This function will return the match of any one of the specified strings seperated by | operator

  • Regex for URL Expression

    I am not a programmer, but I have to write a rule for CACHING the following URL that is being generated with "GET_QUERYSTRING".
    /myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map&mx=198&my=247&request=gettile&zoomlevel=3
    As you can see, I would like to cache all the PNG map tiles, but I don't know how to come up with Regular Expression (regex) for the above URL.
    Thanks,

    are you talking about xml schema restriction?
    <xs:element name="url">
      <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="(https?://)?[-\w.]+(:\d{2,5})?(/([\w/_.]*)?)?" />
       </xs:restriction>
      </xs:simpleType>
    </xs:element>

  • How do i search for a string in a txt file using java??

    How do i search for a string in a txt file using java??
    could you please help thanks
    J

    Regular expressinos work just fine, especially when
    searching for patterns. But they seem to be impying
    it's a specific group of characters they're looking
    for, and indexOf() is much faster than a regex.If he's reading from a file, the I/O time will likely swamp any performance hit that regex introduces. I think contains() (or indexOf() if he's not on 5.0 yet) is preferable to regex just because it's simpler. (And in the case of contains(), the name makes for a very clear, direct mapping between your intent and the code that realizes it.)

  • Regex on a String?

    I have an array of strings. Each string is pretty big. I just want to match it if anywhere in the string there is a word.
    For example 'test'.
    In perl, it would be something like this:
    if ($myString =~ /test/) { print ("Found it\n"); }That works. In java, not so much. I'ved tried 'test', '.*?test.*?' and about a million other combination.
    This is my code:
         boolean isMatch = Pattern.matches("test", myString);
         if (isMatch) { System.out.println("Found it\n"); }

    1.) Using a regex for simply finding some plain text is overkill and prone to problems (what if your simple text contains ".*"?)
    2.) .matches() requires the entire String to match on the regex, you want to use Matcher.find() instead.
    3.) myString.contains("test") would have the exact same result and be a lot easier.
    Edit: if (Pattern.matches(".*test.*"))
    } should have worked (the "?" are unneeded, as the "*" already includes the possibility of zero characters).

  • Matching the string Pattern '/SMB*/'

    Hi Experts,
    I want to match the pattern '/SMB/'. I tried using if lv_str CP '/SMB/' . But even-though lv_str variable has a string with same pattern, if condition is not getting executed. Please help.
    Thanks in Advance.
    Cheers
    Vinod

    Hi Vinod,
    consider the use of REGEX option in FIND/REPLACE command. See the REGEX documentation.
    Can you give any example for a string that should but does not match the pattern '/SMB*/' ?
    Check the documentation [log_exp - Comparison Operators for Character-Like Data Types|http://help.sap.com/abapdocu_702/en/abenlogexp_strings.htm]. This may help.
    Thanks and regards
    Clemens Li

  • Regex for RDF parsing

    Hi.
    I need help with parsing a rdf-format input stream. I want to use regex for parsing.
    The stream looks like this:
    <?xml version="1.0" encoding="ISO-8859-1" ?><rdf:RDFxmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns="http://my.netscape.com/rdf/simple/0.9/"><channel> <title>heise online news</title><link>http://www.heise.de/newsticker/</link><description>Nachrichten aus der Welt des Computers</description></channel><item><title>Scharfe Regeln f?r Chinas Cybercafes</title><link>http://www.heise.de/newsticker/data/gr-12.10.02-004/</link></item>.........</item></rdf:RDF>
    The information i need is placed between the <item></item> tags.
    I have wrote following code to get all subsequences like "<item>...</item>":
    String rval = new String("");
    Pattern p = Pattern.compile("<item[ >](.*)</item>");
    Matcher m = p.matcher(retval);
    while (m.matches()) {
    rval = rval + m.group() + "<br>\n";
    But this loop only once and the output is one large String from the first "<item>" to the last "</item>" like "<item>......</item><br>\n". The <item>...</item> combos within are ignored. Maybe the regex must be change?
    Thanks for answer,
    sushiprinz

    You need to use the non-greedy star:Pattern p = Pattern.compile("<item>(.*?)</item>");Also, I think you want to use find() instead of matches().

  • RegEx, need help with pattern matching

    im going thru a list of Strings...and id like to match some input to it..but the tutorial for regex wont let me find a smaller string within a bigger one if it exists
    for example i have a String "java.sun.com" and i want to find "sun" or "java" or "com" or "jav" or ".co"
    i think the only way regex will work is if i group the entire thing into
    any ideas on how i can manipulate the string into a proper regex pattern so that itll find any of those "searches"
    thanks

    No, that is not correct. A regex can be constructed to return a match on anything you want. A single character, a newline character, a numeric character and any combination of them. There are limitless possibilities for pattern matching.
    See here:
    http://java.sun.com/j2se/1.4.1/docs/api/java/util/regex/Pattern.html
    Any of the patterns may be compiled into a regex for searching using the matcher.
    An alternative is to use the indexOf method of the string class to find what you are looking for.
    Example:
    String myString = "java.sun.com";
    String matchThis = "n.co";
    int patternFoundAtThisIndexPosition = myString.indexof(matchThis);patternFoundAtThisIndexPosition will be 7;
    or simply:
    int index = myString.indexof("sun");index will be 5;

  • How to write code for save file directory?

    how to write code for save file directory?

    how to find usa timezone code using java swing?
    i have some code help me
    public class ItsInitializer {
    private static boolean s_initialized = false;
    private ItsInitializer() {
    public static synchronized void initialize() {
    if (!s_initialized) {
    // Modifies default time zone, disables Daylight Saving Time.
    TimeZone l_defaultTimeZone = TimeZone.getDefault();
    int l_rawOffset = l_defaultTimeZone.getRawOffset();
    String l_id = l_defaultTimeZone.getID();
    SimpleTimeZone l_simpleTimeZone = new SimpleTimeZone(l_rawOffset,
    l_id,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0);
    TimeZone.setDefault(l_simpleTimeZone);
    s_initialized = true;
    2.
    long timeMillis = ...;
    long time = timeMillis / 1000;
    String seconds = Integer.toString((int)(time % 60));
    String minutes = Integer.toString((int)((time % 3600) / 60));
    String hours = Integer.toString((int)(time / 3600));
    for (int i = 0; i < 2; i++) {
         if (seconds.length() < 2) {
              seconds = "0" + seconds;
         if (minutes.length() < 2) {
              minutes = "0" + minutes;
         if (hours.length() < 2) {
              hours = "0" + hours;
    3.
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class Convert {
    public String getDateTime(String pattern){
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    return sdf.format(new Date());
    * @param args
    public static void main(String[] args) {
    Convert con = new Convert();
    System.out.println(con.getDateTime("hh:mm:ss"));
    5.import java.text.SimpleDateFormat;
    import java.util.Date;
    public class Convert {
    public String getDateTime(String pattern){
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    return sdf.format(new Date());
    * @param args
    public static void main(String[] args) {
    Convert con = new Convert();
    System.out.println(con.getDateTime("hh:mm:ss"));
    [ November 23, 2005: Mess
    private Locale locale = Locale.US;
    private static final String[] tzStrings = {
    "America/New_York",
    "America/Chicago",
    "America/Denver",
    "America/Los_Angeles",
    Date now = new Date();
    for ( TimeZone z : zones) {
    DateFormat df = new SimpleDateFormat("K:mm a,z", locale);
    df.setTimeZone(z);
    String result = df.format(now);
    System.out.println(result);
    String date="05/19/2008 04:30 AM (EST)";
                   SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm aaa (z)");
                   TimeZone.setDefault(TimeZone.getTimeZone("PST"));
                   long millis = sdf.parse(date).getTime();
                   sdf.setTimeZone(TimeZone.getDefault());
                   System.out.println(sdf.format(new Date(millis)));
    [ November 23, 2005: Mes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can more than one delimiter be use at the same time for spreadsheet string to array

    I have a text header in my data file that is space delimited and the data in the file is tab delimited? Any suggestion?

    Sorry, I misread your problem...
    Is the header always of a fixed length in terms of the number of lines? Or can you easily find out from the file how long the header is? If so, you could first read just the header and, instead of using spreadsheet to array function, you could parse the header yourself by using the match string function in a While loop with the search value:
    [\s\t]+
    Assuming slash codes are enabled, this string will match any string of one or more spaces or tabs.
    You could then read the rest of the file and format it using spreadsheet to array with the tab delimiter (that is constant, correct?).
    If you need help with that parsing loop let me know and I'll write one for you...
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

Maybe you are looking for

  • Installation problem under AIX 5.3 with Oracle 10g

    Hello, I start an installation in AIX 5.3 machine with oracle 10. I install oracle 10.0 and pathes for oracle 10.2.0.2.0. I also install and all the interim patches through MOpatch utility. I also install the latest R3trans and R3load for unicode ins

  • Memory error after C042 errors on users database

    Hi, We recently have memory error messages on the POA and on the Client. The error seemed to follow several C042 errors: The database function 53 reported error [C042] on user4mn.db Error: Memory error. Memory function failure [8101] User: I cannot f

  • Inspection Lot Creation after UD

    Dear PP/QM Masters, I have question regarding inspection lot creation after UD for the same batch number. There will be several GR during one shift for one SKU with the same batch number. F.E. shift (6 am to 2 pm) at 7 there will be first GR of finis

  • HT4818 Is there any word on when apple will support Windows 8 in bootcamp?

    Hi all, Is there any word on if Apple will officially support W8 using Bootcamp (and not Parrallels etc)? I assume that it will happen once W8 is officially released in October however I was wondering if anyone has any official word. Otherwise, if a

  • Export module in Indesign fails to overprint black

    Hi Everyone. I have a big issue that need help with. I have indesign files for printing that are exported to pdf for imposition. When I open the pdf in acrobat the text that is set to overprint only knocks out, irrespective of the settings I choose i