#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0

    FoxReplace (Java) - Need help with script


    Greetings everyone,

    First of all, I'm sorry if my post is not in the correct "Java" section.
    I am using the add-on "FoxReplace" (which uses json files) on Firefox in order to remove/replace occurrences on websites. However, there is a case I cannot solve and I would like to ask for your help.

    I need to parse the following line:

    "INFO Log - [sys] Area#541185471Character#46545"


    I would like to remove "Area#xxxxxxxxx" (where x are random numbers).

    Being completely new to Javascript, I'm afraid I couldn't find the expressions I'm looking for in order to remove these.

    If you need any other details, please do not hesitate to ask.
    I thank you in advance for your help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    String.replace() is the String method to do regex search-and-replace in javascript. For example

    Code:
    var s = "INFO Log - [sys] Area#541185471Character#46545";
    var s2 = s.replace(/Area#[0-9]+/, "");
    alert(s2);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0
    Thank you very much for your reply.
    Unfortunately, FoxReplace seems to only work with this format:

    {
    "input": "Text to replace",
    "inputType": "regexp",
    "output": "New Text",
    "caseSensitive": true
    },

    Do you think there is a way to use this format with the s.string command?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    I guess you'd use

    {
    "input": "Area#[0-9]+",
    "inputType": "regexp",
    "output": "",
    "caseSensitive": "true"
    }
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0
    Thank you very very much for your help, it works perfectly!
    Now, I just need only one thing to change...

    2013-08-28.txt@INFO
    May I ask how can you remove x characters before a word? I tried a few combination based on [0-9-] but it didn't work...

    I'm sorry for all the newbe questions and thanks again for your help, you're being very helpful.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    I don't understand what part of that string you're trying to match.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0
    Sorry, I was not really clear indeed.

    2013-08-28.txt@INFO
    I would like to match the red part.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    I guess mods should move this to the regex forum if there is such a thing. Anyway, you wanna match a date like YYYY-MM-DD, then a dot, then some letters, a regex for that could be:
    \d{4}-\d{2}-\d{2}\.[a-zA-Z]+

    In this case though it's probably enough to just match anything up to the @:
    [^@]+

    Help yourself out and google some tutorials or whatever on regular expressions. At this point you're not getting anything out of just having me do some for you.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0
    Again, I thank you very much for your help. Everything's working now. I'll do my best to find the information I need if I get another issue (I've tried to find out by myself but I must say the results were not so good since I've never used Javascript before).

    Thanks again and have a very nice day/evening.

IMN logo majestic logo threadwatch logo seochat tools logo