Using Regex to search strings......

Hey guys,
I'm trying to scan an html file for specific strings. Basically, I just store the entire html file as a one big long string and then use a regex to scan the string for specific keywords that I am looking for. However, I am not all that familiar with regular expressions in java, and, although I have spent a considerable amount of time reading over the tutorials, I can't seem to get my regular expression to produce the results that I want.
+More specifically, what I am trying to scan the html string for is a keyword preceded by a non-alphanumeric character([/W] and followed by a non-alphanumeric character. Also, since the keywords generally represent country names, state names, state abbreviations, city names, and the like.....I really want to make the scan case-insensitive to the case format of the keyword except in the case that the keyword is an abbreviation (i.e., CA, IN, NY,etc. since making this case-insensitive would pick up a lot of garbage, especially in cases like: IN)+_.* As of right now, this is what I am using for my regex(and the results are all over the place):
*String regex = "[/W]+"+"(?i)"+keyword+"[/W]+";*
This just seems wrong! I've played around with it and, lets just say, the results have generally gotten worse. Does anyone have any ideas on how I should correctly format the regex to achieve the goal explained above?? Any and all help would be greatly appreciated. Thanks.

A technique I find very useful in writing complex regex's is to split the regex into its parts and work on just the one part at a time. This helps me to easily see that the components match exactly what I think I am matching. Once I have every individual part working it is very easy to join them to create the entire match.
Something like...
String keywordRegex = "";
String nonAlphaCharRegex = "";
//..etc. etc
String fullRegex = keywordRegex + "whateverIwantToMatchBetween" + nonAlphaCharRegex + ...

Similar Messages

  • Creating Bookmarks in form using JavaScript on searched string.

    Hi all,
    I am currently working on SAP Adobe Form to which I need to add bookmarks
    dynamically where the Searched string is found and this should be done during
    its Assembly. Any help is appreciated.
    Edited by: gopbhav on Jul 19, 2010 8:12 PM
    Edited by: gopbhav on Jul 19, 2010 8:28 PM

    Otto,
    We have forms created with bindings as well as document (word document) are being (merged)/populated dynamically.
    After it has been compiled I need to do a search for "string" and where the first "string" is matched I need to add a bookmark to that particular page. Bookmarks are used widely in Acrobat and there is a JavaScript to create bookmark available but the code for Adobe LC/ SAP Adobe Form is different. So I need help if someone knows how I go about do this.
    gopbhav

  • Help using regex to change strings

    I'm writing a utility to move sub folders from computer to computer. I am trying to get regex to work so a string like "d:\\NewScans\\22102\\7-17" would become "\\\\inv108\\data\\users\\clipper\\scan\\22102\\7-17"
    so basically "d:\\NewScans\\" needs to become
    "\\\\inv108\\data\\users\\clipper\\scan\\" Here is the program I wrote taht accepts the input and out put directories like:
    java Paper mover d:\\NewScans \\\\inv108\\data\\users\\clipper\\scan
    This is the code I wrote but it doesn't work:
    /** Created to move files from a remote bureau to MPCB */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.io.OutputStream.*;
    import java.util.regex.*;
    public class PaperMover{
         private File start_path;
         private File destination;
         public static void main(String[] args){
              if(args[0] != null){
                   PaperMover m = new PaperMover(args[0].trim(), args[1].trim());
                   m.move_papers();
              else{
                   System.out.println("no input directory");
                   System.exit(0);
         public PaperMover(String path, String destination){
              start_path = new File(path);
              this.destination = new File(destination);
         public void move_papers(){
              File[] listing = start_path.listFiles();
              File temp;
              String pat = start_path.getAbsolutePath();
              Pattern P = Pattern.compile(pat);
              for(int i = 0; i<listing.length; i++){
                   //get the directories IE 20123
                   try{
                        if(listing.isDirectory()){
                             String t = listing[i].getAbsolutePath();
                             System.out.println(t);
                             String t2 = P.matcher(t).replaceAll(destination.getAbsolutePath());
                             System.out.println(t2);
    I get string t and t2 to be equal.

    I found my troubles!!

  • EBS: Posting on account to Customer  through search string

    We are attempting an on account posting to the customer account based on the customer name in the bank statement. The configuration looks as follows.
    1. Posting rule reflects the setting for posting area 1 and 2. For the second posting area the credit account is blank with posting key 15 and posting type 3
    TL04, 1, 40, BANK,                        50, BANK TRANSITORY, SA, 1
    TL04, 2, 40, BANK TRANSITORY, 15, (BLANK),                    DZ, 3
    2. The search string maps the customer name to customer number
    3. The search string use looks as below
    BDC Account type = 3
    BDC Field name = RF05A-NEWKO
    BDC Field Value = Customer number (as mapped to the search string)
    4. No interpretation algorithm is used both in search string and in assignment of exterrnal transaction types to posting rules
    The second posting to customer cannot be created and it is not able to use the customer number defined n the search string. The value * is passed and goes in error log. Please share your inputs.
    Thanks,
    Rupesh

    Rupesh,
    refer to below link which gives more flexibility by using USER EXIT.
    http://www.se80.co.uk/sapfms/e/exit/exit_rfebbu10_001.htm
    Using exit EXIT_RFEBBU10_001 and structures
    FEBEP or FEBKO or FEBCL . You abapper would help you further.
    Thanks

  • Search string in report variants

    Hi all.
    I'm using RPR_ABAP_SOURCE_SCAN for searching strings in ABAP reports. But now I have to search strings not only in reports but also in variants.
    Does anybody know a report like RPR_ABAP_SOURCE_SCAN for variants?
    Thanks in advance
    christian

    Hi Andreas and Vasanth.
    In principle this fb solve my problem. Unfortunatly, it seems that one of the scanned ABAP reports has an error. The fb abort with message "FORM xxxx doesn't exist."
    Nevertheless, thanks for your support.
    christian

  • Search given string array and replace with another string array using Regex

    Hi All,
    I want to search the given string array and replace with another string array using regex in java
    for example,
    String news = "If you wish to search for any of these characters, they must be preceded by the character to be interpreted"
    String fromValue[] = {"you", "search", "for", "any"}
    String toValue[] = {"me", "dont search", "never", "trip"}
    so the string "you" needs to be converted to "me" i.e you --> me. Similarly
    you --> me
    search --> don't search
    for --> never
    any --> trip
    I want a SINGLE Regular Expression with search and replaces and returns a SINGLE String after replacing all.
    I don't like to iterate one by one and applying regex for each from and to value. Instead i want to iterate the array and form a SINGLE Regulare expression and use to replace the contents of the Entire String.
    One Single regular expression which matches the pattern and solve the issue.
    the output should be as:
    If me wish to don't search never trip etc...,
    Please help me to resolve this.
    Thanks In Advance,
    Kathir

    As stated, no, it can't be done. But that doesn't mean you have to make a separate pass over the input for each word you want to replace. You can employ a regex that matches any word, then use the lower-level Matcher methods to replace the word or not depending on what was matched. Here's an example: import java.util.*;
    import java.util.regex.*;
    public class Test
      static final List<String> oldWords =
          Arrays.asList("you", "search", "for", "any");
      static final List<String> newWords =
          Arrays.asList("me", "dont search", "never", "trip");
      public static void main(String[] args) throws Exception
        String str = "If you wish to search for any of these characters, "
            + "they must be preceded by the character to be interpreted";
        System.out.println(doReplace(str));
      public static String doReplace(String str)
        Pattern p = Pattern.compile("\\b\\w+\\b");
        Matcher m = p.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (m.find())
          int pos = oldWords.indexOf(m.group());
          if (pos > -1)
            m.appendReplacement(sb, "");
            sb.append(newWords.get(pos));
        m.appendTail(sb);
        return sb.toString();
    } This is just a demonstration of the technique; a real-world solution would require a more complicated regex, and I would probably use a Map instead of the two Lists (or arrays).

  • Use of special characters in Search String

    What is the use of special charaters like
    in the search string in the Find & Replace of ABAP editor ?
    I want to search for all strings starting with V which are followed by alphabets like
    VA
    VB...
    If I use V*, it also gives me results like
    V/R...
    Whether it is possible to specify such a condition?

    Hi,
    While giving ur search in FIND & REPLACE,
    use the match case or match whole word only..
    Then u will get search results only where the exact case of that variable is used..
    As per my knowledge there is no signification of special characters ,- : ; in the search string..
    Hope this helps...
    Cheers,
    Simha.

  • How To Color a Text string using Regex (java.util.regex)

    Hello,
    How can I color a text string using regex class in 1.4?

    Yes, did you notice it said something about incredibly vague functionality?
    Let me break it down for you
    > How can I color a text string
    Strings do not have color... You can color a component (a label, a button), but you can't color a string
    > using regex class in 1.4?
    Using a regular expression? How would a regular exression color anything? Do you have embedded color codes? Are you searhing a string for some secret word?
    What are you talking about?

  • How is it possible to use Index Seek for LIKE %search-string% case?

    Hello,
    I have the following SP:
    CREATE PROCEDURE dbo.USP_SAMPLE_PROCEDURE(@Beginning nvarchar(15))
    AS
    SELECT * FROM HumanResources.Employee
    WHERE NationalIDNumber LIKE @Beginning + N'%';
    GO
    If I run the sp first time with param: N'94', then the following plan is generated and added to the cache:
    SQL Server "sniffs" the input value (94) when compiling the query. So for this param using Index Seek for AK_Employee_NationalIDNumber index will be the best option. On the other hand, the query plan should be generic enough to be able to handle
    any values specified in the @Beginning param.
    If I call the sp with @Beginning =N'%94':
    EXEC dbo.USP_SAMPLE_PROCEDURE N'%94'
    I see the same execution plan as above. The question is how is it possible to reuse this execution plan in this case? To be more precise, how
    Index Seek can be used in case LIKE %search-string% case. I expected that
    ONLY Index Scan operation can be used here.
    Alexey

    The key is that the index seek operator includes both seek (greater than and less than) and a predicate (LIKE).  With the leading wildcard, the seek is effectively returning all rows just like a scan and the filter returns only rows matching
    the LIKE expression.
    Do you want to say that in case of leading wildcard, expressions Expr1007 and Expr1008 (see image below) calculated such a way that
    Seek Predicates retrieve all rows from the index. And only
    Predicate does the real job by taking only rows matching the Like expression? If this is the case, then it explains how
    Index Seek can be used to resolve such queries: LIKE N'%94'.
    However, it leads me to another question: Since
    Index Seek in
    this particular case scans
    all the rows, what is the difference between
    Index Seek and Index Scan?
    According to
    MSDN:
    The Index Seek operator uses the seeking ability of indexes to retrieve rows from a nonclustered index.
    The storage engine uses the index to process
    only those rows that satisfy the SEEK:() predicate. It optionally may include a WHERE:() predicate, which the storage engine will evaluate against all rows that satisfy the SEEK:() predicate (it does not use the indexes to do this).
    The Index Scan operator retrieves
    all rows from the nonclustered index specified in the Argument column. If an optional WHERE:() predicate appears in the Argument column, only those rows that satisfy the predicate are returned.
    It seems like Index Scan is a special case of Index Seek,
    which means that when we see Index Seek in the execution plan, it does NOT mean that storage engine does NOT scan all rows. Right?
    Alexey

  • Using EBS search strings to allocate a customer profit center

    Hi All,
    I am using IHC for my incoming payments. I use substitution for profit centers in customer orders, I would like the EBS to automatically deposit into the customer's account using the same profit center used when creating the customer orders. I have been researching on the use of search string, whoever am failing to see how to set this up.
    Any suggestion is greatly appreciated.
    Thanks & Regards,
    Godhelp

    Hi Shannon,
    Thanks for your response.  Here are the results of my latest test.
    I set the algorithms in both the transaction mapping and the search string allocation to "021".  FEBSTS did not find the imbedded reference numbers.
    I left the algorithms in the transaction mapping at "021", but added "000" to the search string allocation (so that both "000" and "021" were active there).  FEBSTS did execute the search strings and returned the reference numbers.
    Unless there is some magic somewhere or I am really misunderstanding something, all of my tests are telling me that the simulation (and presumably the live program) will NOT execute the search strings properly unless "000" is active in the search string functionality, and that means the document retrieval must be done in the user exit.
    This may be part of why SAP recommends that one does not use MT940, but one must deal with what one has.
    Patricia

  • Using Search Strings

    Dears
    We have a scenario where bank is using NTRF both for check and Bank Transfer. Only way to distinguish that it is check is that immediately after External Transaction the check number is of 6 character otherwise it is Bank Transfer. In the EBS configuration with each External Transaction we can assign only one Posting Rule and algorithm. 
    We come to know that through search strings we can change the posting rule and algoritham. We went to many answer on net to work on search strings but so far nothing successful. Can someone guide us how to use it.
    Thanks

    Hi Expert,
    Please refer to the below link which will help in configuring Search Strings for your scenario.
    http://help.sap.com/saphelp_46c/helpdata/es/af/0a242bc925d311b60f0060b03c2bff/content.htm
    http://help.sap.com/saphelp_46c/helpdata/en/6d/0cdf4b142e11d3963800a0c9426c73/content.htm
    Regards,
    GK
    SAP

  • EBS-  How to map search string using wild card

    Hi Gurus
    I got two similar string on bank statement which needs to be mapped to two different posting rules.
    MV-WORLDPAY- 1805 MOTO
    MV-WORLDPAY -1805 WEB
    in above string 1805 could be any no,( it is not fix no). I have tried using different wildcards and symbols like
    +,*,?,# but it is not piciking the right posting rule, also search string use is also activated. so please guide me.
    Many Thanks
    Sam Rathod.

    Hi
    Try keeping the 1st two digits of search string as b;ank. i.e. ############ (12 digits) mapped to __##########. I used underscore to denote balnk space. Using this when you recevie say 000000001618 (12 digits), it will be mapped to 0000001618 (10 digits). Then your interpretation algo will use this 10 digit number.
    Thanks
    Nikhil

  • Extract the numbers in string using regex

    Hi,
    How to extract the numers in string using regex?.
    Already i tried split up the string using [\\s]
    For ex: "Uting Tatk and Window Panet 15"
    it gives the ans 15.
    if the string is
    For ex: "Uting Tatk and Window Panet 15 New!"
    i can't find the number.
    so plz give me some idea to get the number frm String.
    Thanks

    I am developing a java project to extract Table of
    content in a particular
    PDF.
    i extracted all topics.
    then i want 2 extract page number from dat extracted
    TOC.
    if the TOC ends with number then i can easily find
    out the number
    but in vain if the TOC ends with like this
    "Uting Tatk and Window Panet 15 New!".
    i could n't find the page number.What will you do if it says:
    "15 ways to find topics 42 new"

  • Posting rule to be specified in target field of mapping area/Mapping prefix in Search string use?

    Posting rule change using search string configuration
    Hello Friends - I have defined Search string and specified Posting rule in target field of mapping area and set up done on Search search use tab.
    When I imported the Statement, based on text found on statement, Posting rule specified in Search string is determined.
    I see Search strings already maintained in my system that Posting rule is maintained in Search string use tab - Mapping prefix.
    My doubt is that if Posting rule can be maintained in any of the below:
    Either at Posting rule to be specified in target field of mapping area or Mapping prefix in Search string use?
    Thanks

    Hello Kalim - Thanks. I have already configured Search string the way you suggested me last time and imported the statement during testing. It is working fine.
    Can you pls tell me in which scenario "mapping prefix field" should be maintained. Now, I will try to understand this from F1 help.
    For Search Strings already defined in our System long ago that Posting rule is not specified in Target field in mapping field, but maintained Mapping prefix.
    Thanks,
    GT

  • Blueprint shouldn't use entire lines of code as the search string.

    If I have the editor open on some MXML code, and a range of characters is selected in the editor, then invoking Blueprint uses the selected text as the search string. This seems like the right thing to do.
    However, if there is NO text selected, Blueprint uses an entire line of code as the search string (whatever line the insertion point happens to be in). I my experience this is almost always wrong, because (a) most lines of code e.g. "}" or "allPanels[1] = new LayersPanel();" or "private var allPanels : Dictionary = new Dictionary(); do not usually produce very useful search results, and (b) because these strings clutter up the search history.

    Thanks for the suggestion!
    We will reevaluate the use case for using an entire line of code as a query.
    Mira Dontcheva
    Research Scientist
    Adobe Systems

Maybe you are looking for

  • Report Comparing Purchase Requisition Qty vs Delivery /Receipt Qty

    There is a requirement for comparison of Purchase Requirement Qty vs Delivery Qty . The Purchse order will be created with ref to Purchase Requisition but change of PO Qty is allowed . There is also an option to make Po without ref to PR . Thanks San

  • Business Content Extractor for SAP Controlling ?

    Hi all,   I would like to know if there is an existing Business Content Extractor's for SAP BW for CONTROLLING - INTERNAL ORDERS.   What I need to be available from SAP R/3 can be accessible via :-   SAP R/3 -> Accounting -> Controlling -> Internal O

  • Excise Report Print Config

    Hi, Can somebody throw a detailed configuration setting on Excise report printing in J1IV transaction? My concern is my own customised series group is not appearing in the selection list. To be more precise i wanted to know the config setting of seri

  • ITunes not updating audio files on iPhone 4s

    On Mac 10.7.2, iTunes 10.5.1, and iOS 5.0.1. I have made changes to the genre of a few of my audio files but they are not updating on iTunes. iTunes appears to go through the entire process of syncing but no changes are made. I'm assuming I'm not the

  • Iphone 3g working very slow

    Hi, I am using the Iphone 3G with 4.2.1 OS My phone working very slow, also i can close the application i have to restart the iphone for closing the application Can you please help me to solve this issue with best regards, prakash