How to write regular expression to get the substring from the string using regular expression in c#?

MANISH KUMAR CHOUDHARY

I have following string

string s=@"\Users\Public\Roaming\Intel\Wireless\Settings"; 

I want output string like

string output="Wireless";

Sub-string what I want should be after "Intel\" and it should ends with the first "\" after "Intel\" before string Intel and after Intel the string may be different. I have achieved it using string.substring() but I want to get it using regular expression ? what regular expression should I write to get that string.

Wiktor Stribiżew

With regex, it will look like

var txt = @"\Users\Public\Roaming\Intel\Wireless\Settings";
var res = Regex.Match(txt, @"Intel\\([^\\]+)", RegexOptions.IgnoreCase).Groups[1].Value;

But usually, you should use string methods with such requirements. Here is a demo code (without error checking):

var strt = txt.IndexOf("Intel\\") + 6;   // 6 is the length of "Intel\"
var end = txt.IndexOf("\\", strt + 1);   // Look for the next "\"
var res2 = txt.Substring(strt, end - strt); // Get the substring

See IDEONE demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regular Expression to get substring from main string

From Dev

How to find a substring from a string using regular expression in php?

From Dev

How to get domain from a string using javascript regular expression

From Dev

How to get domain from a string using javascript regular expression

From Dev

How to get string from parenthesis using regular expression in python

From Dev

how to get specific value from a string by using regular expression

From Dev

Need to get so substring but using Regular Expression

From Dev

How to retrieve substring form a string using regular expression in python

From Dev

How i can extract substring from string using regular expression in .NET

From Dev

How to write this as a regular expression

From Dev

How to write regular expression

From Dev

Using a regular expression to extract substring

From Dev

How to write the proper regular expression to extract value from the string?

From Dev

Regular expression for a substring from a line

From Dev

regular expression from string

From Dev

regular expression from string

From Dev

How to substring Regular expression in JavaScript

From Dev

How find substring with regular expression

From Dev

Get a particular string from a data using regular expression

From Dev

Get a word using php regular expression from string

From Dev

Write a regular expression in order to search a substring C#

From Dev

c# how to write Regular Expression filter

From Dev

get the first parameter of a string using regular expression

From Dev

How to get a regular expression

From Dev

regular expression to get a particular string from a data

From Dev

How to get the days out of a string using Regular Expression in Python?

From Dev

how to get all string lines using regular expression in python

From Dev

Extract sentence from html string using Regular Expression in C#

From Dev

Write a Regular Expression in Python to match substring

Related Related

  1. 1

    Regular Expression to get substring from main string

  2. 2

    How to find a substring from a string using regular expression in php?

  3. 3

    How to get domain from a string using javascript regular expression

  4. 4

    How to get domain from a string using javascript regular expression

  5. 5

    How to get string from parenthesis using regular expression in python

  6. 6

    how to get specific value from a string by using regular expression

  7. 7

    Need to get so substring but using Regular Expression

  8. 8

    How to retrieve substring form a string using regular expression in python

  9. 9

    How i can extract substring from string using regular expression in .NET

  10. 10

    How to write this as a regular expression

  11. 11

    How to write regular expression

  12. 12

    Using a regular expression to extract substring

  13. 13

    How to write the proper regular expression to extract value from the string?

  14. 14

    Regular expression for a substring from a line

  15. 15

    regular expression from string

  16. 16

    regular expression from string

  17. 17

    How to substring Regular expression in JavaScript

  18. 18

    How find substring with regular expression

  19. 19

    Get a particular string from a data using regular expression

  20. 20

    Get a word using php regular expression from string

  21. 21

    Write a regular expression in order to search a substring C#

  22. 22

    c# how to write Regular Expression filter

  23. 23

    get the first parameter of a string using regular expression

  24. 24

    How to get a regular expression

  25. 25

    regular expression to get a particular string from a data

  26. 26

    How to get the days out of a string using Regular Expression in Python?

  27. 27

    how to get all string lines using regular expression in python

  28. 28

    Extract sentence from html string using Regular Expression in C#

  29. 29

    Write a Regular Expression in Python to match substring

HotTag

Archive