Parsing Movie title with RegEx [closed] - c#

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 8 years ago.
Improve this question
I have 3 strings from wich I want to extract the movie title, if posible in one RegularExpression
<title>Airplane! (1980)</title>
<title>"24" (2001)</title>
<title>"Agents of S.H.I.E.L.D." The Magical Place (2014)</title>
My best shot so far is this one:
<title>(")?(.*?)(")?.*?\((\d{4})\).*?</title>
Works fine for "Agents of S.H.I.E.L.D." and "24" but not for "Airplane!".
What am I doing wrong?
Even though it might not be clear the regular expression are called within a C# program, and I'm using RegEx

RE for start-of-line => opening tag => optional " => read until " or (nnnn)
titles = System.Net.WebUtility.HtmlDecode(titles);
foreach (Match match in Regex.Matches(titles,
#"^\s*<title>\s*\""*(.*?)(\""|\(\d{4}\))", RegexOptions.Multiline | RegexOptions.IgnoreCase))
{
if (match.Success)
{
string name = match.Groups[1].Value;
}
}

Related

Extract title from name in c# [closed]

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
How do I extract title from name as Mr. from Mr.ABC or Dr. from Dr.XYZ or M/S. from M/S. PQR in C#?
I would recommend regex for a clean way to get the title.
Regex regex = new Regex(#"^(Mr|Ms|Dr|Sr)\.");
Match match = regex.Match("Mr.ABC");
Console.WriteLine(match.Value);
You can split the string on '.' and then take the first value.
string str = "Mr.ABC";
string title = str.Spilt('.')[0];
There is no need to use regex.
Use String Split method:
var title = myString.Split('.')[0];

How i can get the first match in regex and import this match in a string? [closed]

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
For example using a regex expression del(.*?)del get delcatdel
and save the result in string or in text
word1word2delcatdelword3word4deldogdelword5
in my text (or string) i need obtain delcatdel
USING c sharp
please anybody help me
var regex = new Regex("del(.*?)del");
var match = regex.Match("word1word2delcatdelword3word4deldogdelword5");
string matched = match.Value;

Regular expression to search for files and folders [closed]

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 7 years ago.
Improve this question
Help write a regular expression to search for files and folders,
searches for a given mask. In the mask, you can use "*"
(any characters in any number), and the "?" (one symbol).
Here shows you how to use regex in C#.
You could always just loop the directory that you're looking in and check the file names instead of making a regex. (You'll need to use System.IO)
Perhaps something like this?
string [] fileEntries = Directory.GetFiles(targetDirectory);
Regex regex = new Regex("target file name");
Match match = regex.Match(string.Join(" ", fileEntries););
if (match.Success)
{
Console.WriteLine(match.Value);
}

C# Regex questions [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 8 years ago.
Improve this question
How can I extract the word "Word" (or any word) using Regex into a string in both cases? in the following string:
Word = CreateObject(980, -1696.5996, -12.2998, 5.3, 0, 0, 317.999);
MoveObject(Word, -1660.9004, 79.40039, 2.2,6);
I am pretty new in Regex, and I am having hard time understanding the tutorials over the internet.
I have tried using /(.*)( = CreateObject)/ but no luck
Tried using /MoveObject\(.*?\,/ and it works, but it matches MoveObject too, and I want it to match only "Word"
Thanks!
You could try the below regex.
#".*?(?= = CreateObject)|(?<=MoveObject\().*?(?=,)"
OR
#"\S+?(?= = CreateObject)|(?<=MoveObject\().*?(?=,)"
DEMO

Simple solution for #"\b \b" [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 am trying read one string from TextBox and use in my script.
Suppose this TextBox name is: txt3.
I want read this value and use in below lines:
string s = Regex.Replace(str,
#"\btxt3.Text\b",
txt4.Text,
RegexOptions.IgnoreCase);
How I can write this #"\btxt3.Text\b" ?
I want write that as :
string str==#"\btxt3.Text\b";
You want something like:
String.Format(#"\b{0}\b", txt3.Text)
Try this
string s = Regex.Replace(str, string.Format(#"\b{0}\b",txt3.Text), txt4.Text, RegexOptions.IgnoreCase);
If you want to combine value of txt3 with other strings, one way to do it is write
"\\b" + txt3.Text + "\\b"
instead of
#"\btxt3.Text\b"

Categories