How do I get the first group of alpha characters from string?

user1

If I have a string how do I extract the first alpha characters from the string such that I end up with the starting alpha characters or an empty string. E.g:

AB12 9HG => "AB"
PJ11 => "PJ"
123JO => ""

Is this possible with regex or is there an easier way?

Wiktor Stribiżew

You can use LINQ to build the result:

new String(s.TakeWhile(p => Char.IsLetter(p)).ToArray());

Basically, just take the characters from the start until the first non-alpha char.

If there is leading whitespace, Trim() the string first.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I remove the first n characters from a string in c?

From Dev

How do I get first three characters from an edittext?

From Dev

How do I retrieve the first alpha character string from withing a longer string using c#

From Dev

How do I get individual number of characters, digits from a string?

From Dev

How do I get the first character of a string from a linked list?

From Dev

how do i remove the first characters of a string [python]

From Dev

How to I get the first or last few characters of a string in a method chain?

From Dev

How can i do Group by an property and get first record from any groups with lambda linq?

From Dev

How can I remove from string the four first characters? iMacros

From Dev

How do i write a regex for verifying a string that contains exactly 4 alpha 7 numeric characters respectively

From Dev

how do i get last result in group by MySQL query (not the first)

From Dev

Get leading alpha characters from a string in Java/Groovy

From Dev

How do I get the first and last initial/character from a name string

From Dev

How to get the length of alpha-numeric characters in a string in PHP?

From Dev

How do I remove multiple offending characters from my string?

From Dev

How do I create a dictionary from a string returning the number of characters

From Dev

How do I remove new line characters from a string?

From Dev

How do I remove the last characters from a string?

From Dev

How can I get 2 characters from the middle of a string?

From Dev

How can I get the number of characters from an input string?

From Dev

How can I get 2 characters from the middle of a string?

From Dev

How can I get several characters from a std::string

From Dev

How do I get the length of the first line in a multi line string?

From Dev

How do I split the getActionCommand() in order to get the first element in the string?

From Dev

How do I get the the first character of an already initialized string in PHP?

From Dev

SSRS Chart Group Series - How do I get the secondary series group to start at the first data point?

From Dev

How do I generate an html string from group by

From Dev

How can I get only the first line from a string?

From Dev

How do I get a group from a partially failing Regex

Related Related

  1. 1

    How do I remove the first n characters from a string in c?

  2. 2

    How do I get first three characters from an edittext?

  3. 3

    How do I retrieve the first alpha character string from withing a longer string using c#

  4. 4

    How do I get individual number of characters, digits from a string?

  5. 5

    How do I get the first character of a string from a linked list?

  6. 6

    how do i remove the first characters of a string [python]

  7. 7

    How to I get the first or last few characters of a string in a method chain?

  8. 8

    How can i do Group by an property and get first record from any groups with lambda linq?

  9. 9

    How can I remove from string the four first characters? iMacros

  10. 10

    How do i write a regex for verifying a string that contains exactly 4 alpha 7 numeric characters respectively

  11. 11

    how do i get last result in group by MySQL query (not the first)

  12. 12

    Get leading alpha characters from a string in Java/Groovy

  13. 13

    How do I get the first and last initial/character from a name string

  14. 14

    How to get the length of alpha-numeric characters in a string in PHP?

  15. 15

    How do I remove multiple offending characters from my string?

  16. 16

    How do I create a dictionary from a string returning the number of characters

  17. 17

    How do I remove new line characters from a string?

  18. 18

    How do I remove the last characters from a string?

  19. 19

    How can I get 2 characters from the middle of a string?

  20. 20

    How can I get the number of characters from an input string?

  21. 21

    How can I get 2 characters from the middle of a string?

  22. 22

    How can I get several characters from a std::string

  23. 23

    How do I get the length of the first line in a multi line string?

  24. 24

    How do I split the getActionCommand() in order to get the first element in the string?

  25. 25

    How do I get the the first character of an already initialized string in PHP?

  26. 26

    SSRS Chart Group Series - How do I get the secondary series group to start at the first data point?

  27. 27

    How do I generate an html string from group by

  28. 28

    How can I get only the first line from a string?

  29. 29

    How do I get a group from a partially failing Regex

HotTag

Archive