Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6338919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:32:37+00:00 2026-05-24T19:32:37+00:00

I need to use a replace function in Java: string.replace(myString,); myString values are for

  • 0

I need to use a replace function in Java:
string.replace(myString,"");
myString values are for example javascript:r(0), javascript:r(23), javascript:l(5) etc. Just number is always different and there is r or l letter. What’s the regular expression to match it? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:32:38+00:00Added an answer on May 24, 2026 at 7:32 pm

    (FIXED) The regex you want is

    "javascript:[rl]\\(\\d+\\)"
    

    NOTE: The outer quotes aren’t really part of the regex; they are part of the Java string you pass to Pattern.compile or directly to replace.

    Here is a complete program you can try:

    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    
    public class PatternExample {
        private static final Pattern JS_PATTERN = Pattern.compile("javascript:[rl]\\(\\d+\\)");
        private static final String[] MESSAGES = {
            "Good javascript:r(5)",
            "Good javascript:l(50003843)",
            "Good javascript:r(1123934)",
            "Bad javascript:|(5)",
            "Bad javascript:r(53d)",
            "Bad javascript:l()",
        };
        public static void main(String[] args) {
            for (String s : MESSAGES) {
                Matcher matcher = JS_PATTERN.matcher(s);
                System.out.println(matcher.replaceAll(""));
            }
        }
    }
    

    Here is another version of the above program that calls replaceAll directly on the string instead of pre-compiling the pattern:

    public class PatternExample {
        private static final String[] MESSAGES = {
            "Good javascript:r(0)",
            "Good javascript:l(50003843)",
            "Good javascript:r(1123934)",
            "Bad javascript:|(5)",
            "Bad javascript:r(53d)",
            "Bad javascript:l()",
        };
        public static void main(String[] args) {
            for (String s : MESSAGES) {
                System.out.println(s.replaceAll("javascript:[rl]\\(\\d+\\)", ""));
            }
        }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use the replace function on my subject line when sending an
I need to use .htaccess file to replace a word in a URL; something
I have a query in java string. What i need to do is fire
I'm writing a function that I need to use either a TABLE variable for
I am working with XSLT 1.0 (so I can't use the replace() function), and
I want to use a c# function which modifies a string for html valid
I need to be able to replace certain characters so that I can use
Hi i need to strip all spaces and newlines from a string in javascript...
what can I use to replace the string if its in the following format
Need to use own imaged markers instead built-in pins. I have several questions. 1.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.