I was recently asked this in an interview question: Given a input string check if it has repeating pattern and return true or false. For example: “abbaabbaabbaabba” is a repeating pattern of “abba” How can we solve it using regex and also without regex? I am interested in both the approaches with regex and without regex. Answer Without regex, you
Tag: regex
How do I get the first and last initial/character from a name string
I am trying to extract the first character of both first and last name from a string but have had no luck so far.( tried searching multiple solutiosn online, no luck either) So for example, if this is the string: I want to display just A and E ( say AE). I am trying to figure out if theres an
Free space regex option (Pattern.COMMENTS) not working as expected
I’m trying to detect profanity using regex. But I want to detect the word even if they’ve spaced out the word like “Profa nity”. However when using the “(?x)” option it still doesn’t want to detect. I currently got: I’ve tried using http://www.rubular.com to debug the expression with not luck. If it helps in any way it’s for at Teamspeak
Remove character ‘u202A’ 8234 from string
I am trying to get character at 0 index in a string: So I use this function after I query contact, but I found strange result. Normal input & output: And this the strange input and result: So I try to debug this account and I found when app try to get character at 0 the return is ‘u202A’ 8234,
Java Regex First Name Validation
I understand that validating the first name field is highly controversial due to the fact that there are so many different possibilities. However, I am just learning regex and in an effort to help grasp the concept, I have designed some simple validations to create just try to make sure I am able to make the code do exactly what
Java Stream filter with regex not working
hope somebody can help me. I have a ArrayList of a Invoice class. What I’m trying to get is to filter this ArrayListand find the first element which one of its properties matches with a regex. The Invoiceclass looks like this: I’m filtering with this regex (\D+) in order to find if there is any value in the orderNumproperty that
how to remove Arabic hashtags?
I am polling tweets from twitter using Twitter4j and I am trying to filter hashtags from it after I take text from it I turn it into strings now I have this String: “892698363371638784:RT @hikids_ksa: اللعبة خطيرة مرا ويبي لها مخ و تفكير و مهارة👌🏻💡 متوفرة في #متجر_هاي_كيدز_الالكتروني ..” I want to remove متجر_هاي_كيدز_الالكتروني as it has Hashtag after it
How to check if only one ‘@’ symbol in email address using regex in java?
I am trying to create a regex in java to validate the email address. It should contain one uppercase one lowercase one digit only one @ symbol followed by ‘.’.So far i could only create this, scenarios like these abC.8@gmailcom this address should return false abC8@@gmail.com this also should return false But the above regex returns true for all these
Java regex does not match as expected
I’m starting with regex in Java recently, and I cant wrap my head around this problem. Result: Did not Match(Unexpected result) Explain this I get the output “Did not match.” This is strange to me, while reading https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html, I’m using the X+, which matches “One, or more times”. I thought my code in words would go something like this: “Check
How to count the characters in a String that matched a given Regex
Given an arbitrary String that contains 0 or more Substrings that match a regular expression. How can I count the number of characters in that String that were part of Substrings that matched the regex? Example: Given a regex that matches any email address and the String: This would return the int value of 32 (the number of characters in