Regular Expression for " - " and characters after [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
This is a question for experts on regular expressions, since it is something that I dont have much insight.
Its not C#, java specific, its a general regular expression that I need to put in one application that will rename files.
Basically I have structures of folders like this.
1 - I went to the cinema 1
I went to the cinema 1 - movie title 1
I went to the cinema 1 - movie title 2
I went to the cinema 1 - movie title 3
I went to the cinema 1 - movie title 4
2 - I went to the cinema 2
3 - I went to the cinema 3
I need an expression that pretty much returns the text after " - " because everything is before is the parent folder name.
May be a simple question but I did some search and I can't find it.
Thanks

You can use the regex -(.*), see live demo

You can use a simple regex, since the "-" character is not a special character used outside the square brackets.
You can use this - *(.*)
This is very similar to Thomas Ayoub answer, but I think you're not interested in the trailing space.
If you're sure that the space will always be there, and maybe you want to avoid other "-" inside the string to give unexpected results, you can use this: - (.*) (there's a space before the "-", so it will fine all the test after " - "
See live demo

Related

Questions about using regular expressions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to learn more about regex and I'm running into a block
my current query:
function telephoneCheck(str) {
return str.match(/[0-9]{3}[-][0-9]{3}[-][0-9]{4}/g)? true : false
}
This will only work for a specific inputs such as "555-555-5555", but for other inputs such as "1 (555) 555-5555" it will not. I'm at a loss on how to query for optional characters and whitespace. Moreover bracket handling is odd and I've found some crazy queries such as /(\d+-)\1\d{4}/g but I have no idea what its doing and I don't want to use code I don't understand.
Can someone show me a query that solves for "1 (555) 555-5555" where the first two characters (the one and space) are optional inputs?
These are inputs that the regex should be able to handle:
"1 (555) 555-5555"
"1(555)555-5555"
"1 555-555-5555"
"555-555-5555"
"(555)555-5555"
"5555555555"
I found a solution
regex: function telephoneCheck(str) {
var regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/;
return regex.test(str);
}
telephoneCheck("555-555-5555");
But I have no idea whats going on in here. If someone could explain whats happening I'd be happy to give you the answer for this posted question :)
You have be wary of trying to be all things within regex and question why the data is so varied in the first place.
If you are just parsing a bunch of what you are thinking should be phone numbers for example and notice a lot of different formats it might actually be more readable to use logic.
There is probably a really clever way of doing the above but I tend to be a bit more brute force with regex until I need more.
The below combines both patterns in to one regex expression. You use the | separator to say or. Also if your strings are exactly as you say, you should to use the ^ (starts with) and $ ends with to ensure you don't get false positives.
var pattern = /^[0-9] \([0-9]{3}\) [0-9]{3}-[0-9]{4}$|^[0-9]{3}[-][0-9]{3}[-][0-9]{4}$/
pattern.test('555-555-5555') //true
pattern.test('1 (555) 555-5555') // true
pattern.test('(555) 555-5555') // false
And as I say if you have lots of different formats in one. Question why, is there a way to clean things up first. Then perhaps use logic and separate statements.
var parensPattern = /^[0-9] \([0-9]{3}\) [0-9]{3}-[0-9]{4}$/
var noParensPattern = /^[0-9]{3}[-][0-9]{3}[-][0-9]{4}$/
if(parensPattern.test('1 (555) 555-5555')) {
// do something
} else if (noParensPattern.test('555-555-5555)) {
// do something
}
Check out http://regex101.com, it is a great resource.

Place Commas Between Numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I'm having trouble getting this to work in AS3, I want to place a comma between numbers only when their is a whitespace.
For example, if the string is "1.23 5.34" I want it to become "1.23, 5.34". The trouble is the white space varies and the number may or may not contain a decimal. So, I'd want "1 1.4" to become "1, 1.4" or "2.3 4.5" to become "2.3, 4.5". This also includes negative numbers, so "1.4 -15.3" should become "1.4, -15.3". If there is anything but a number on either side of the white space, I'd want to skip that space and not effect it. So "Car 35.2" would be skipped and so would (13.5 ).
I've tried several Regexs found around the net and did my best with the limited regex knowledge I have, any help would be greatly appreciated.
Thanks.
UPDADE
(?<=\d)(\s)(?=-?\d) (thanks for your comment Tim)
Try the folowing pattern:
"(?<=\d)(\s)(?=[\d-])" (edited to include negative ones)
replace for ",$1"
youre essentially replacing " " with ", "
var value:String = "1 2 -3 4 -5";
var csvValue:String = value.split(" ").join(", "); // will print out "1, 2, -3, 4, -5"

Recognizing patterns given a set of sentences [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a text file with lots of sentences. These sentences can occur in patterns. How do I recognize these patterns?
For example:
i woke up in the morning
i went to school
i played football
i came back home
i woke up in the morning
i went to school
i played basketball
At this point I want the program to say that "I played football" should have appeared.
This task seems to little bit complicate,but you can try this simple code for understanding or if finds it useful you can further implement it::
//the sentences/input input String
String sampleString1="xyz";
String[] sampleString2=sampleString1.split(".");
for(int i=1;i<=sampleString2.length;i++){
//The pattern which you can specify to match with the sentence
if(sampleString2[i].substring(0, 14).equals(sampleString2[0].substring(0,16))){
//code to execute the matched sentence.
System.out.println("Sentence matching with pattern ::" + sampleString2[i]);
}
}
If the pattern to be matched is the first line of the sequence ,then try this code.

Notepad++ find and replace after specific character [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have hundred of song lyric database files, and I need to do something like this,
from this :
PPK4: B'rilah Hormat Pada Hu
Judul Inggris: Glory to God in the Highest
Lagu: unknown Syair: unknown
1=A, 4/4
to become like this :
PPK4: B'rilah Hormat Pada Hu
B'rilah Hormat Pada Hu
Judul Inggris: Glory to God in the Highest
Lagu: unknown Syair: unknown
1=A, 4/4
PPK4 is a song number. so, there will be like PPK1 until PPK255, KPPK1 .. KPPK300 etc.
and same format, "#songcode" ":" "(space)" "song title" "CRLF"
How do I do it using Find and Replace?
The answer involves regular expressions.
You could try "([A-Z]+[0-9]+[:])(.*)"
This will capture the song number as group 1 and the song title as group 2. You can then replace this with "\1\2\n\2", i.e. group 1 followed by group 2, a newline and group 2 again.

RegEx ActionScript 3 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to figure out a regex to strip extra single quotes so that I would end up with only one single quote. To explain my question better, here is an example.
Let's say I have 3 different strings such as this ones.
(two single quotes)
Name<span fontSize=''16'' baselineShift=''superscript''>ABC</span>
(three single quotes)
Name<span fontSize='''16''' baselineShift='''superscript'''>ABC</span>
(four single quotes)
Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>
I am trying to sanitize the string to end up with this:
Name<span fontSize='16' baselineShift='superscript'>ABC</span>
I tried several online tools. This one is my favourite one: http://ryanswanson.com/regexp/#start. But I just can't get it right.
Could someone please help me out? Any tips and suggestions would be greatly appreciated.
Thank you in advance!
Did you try '+?
var str:String = "Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>";
trace( str.replace(/'+/g, "'") );
Have you looked at the docs for AS3's RegEx code? AS3 Replace
You could try something like this
var myPattern:RegExp = /'{2,100}/g;
var str:String = "fontSize=''''16''''";
trace(str.replace(myPattern, "'"));
The '{2,100} essentially looks for a match of ' that occurs between 2 - 100 times and replaces it with a single '.