Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Regular expression for City name

Regular expression for City name

Scheduled Pinned Locked Moved Regular Expressions
regexquestion
15 Posts 7 Posters 69 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KiranKumar V 2024
    wrote on last edited by
    #1

    I have two scenarios in table one is name of person and another is cityname but both name of the person and cityname starts with capital letter and followed by small letters I want different regular expression for cityname and name of person but both starts with capital letter and followed by small letters how can I differentiate them with regular expression.

    D K P J 4 Replies Last reply
    0
    • K KiranKumar V 2024

      I have two scenarios in table one is name of person and another is cityname but both name of the person and cityname starts with capital letter and followed by small letters I want different regular expression for cityname and name of person but both starts with capital letter and followed by small letters how can I differentiate them with regular expression.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This makes no sense at all. What you've said is you have Person names and City names, both using the sexact same format, a capital letter followed by lower-case letters. There is no way to "differentiate them", whatever that means, with a single RegEx. You're going to have to do a better job of explaining what the data you're dealing with is like, and a much better explanation of what you mean by "differentiate them."

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

      K 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This makes no sense at all. What you've said is you have Person names and City names, both using the sexact same format, a capital letter followed by lower-case letters. There is no way to "differentiate them", whatever that means, with a single RegEx. You're going to have to do a better job of explaining what the data you're dealing with is like, and a much better explanation of what you mean by "differentiate them."

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

        K Offline
        K Offline
        KiranKumar V 2024
        wrote on last edited by
        #3

        I am working with Data masking in test data management there we are using one tool called javelin workflow to extract data from XML which is inserted into database and To read data we are using regular expression pattern for name and cityname. But our requirement is city name like Birmingham should be masked as fixed value as Norwich and name of person should be masked as random letters, but we are using same regular expression pattern for both and data is not masking as we expected so we want to differentiate them with regular expression

        D 1 Reply Last reply
        0
        • K KiranKumar V 2024

          I have two scenarios in table one is name of person and another is cityname but both name of the person and cityname starts with capital letter and followed by small letters I want different regular expression for cityname and name of person but both starts with capital letter and followed by small letters how can I differentiate them with regular expression.

          K Offline
          K Offline
          k5054
          wrote on last edited by
          #4

          Based on your description, it would seem that New York is not a valid name for either a person or a city. I'm pretty sure it is a city. So is Stoke-on-Trent. There's probably other names for both people and cities that don't fit your expected pattern. Consider, is Regina a person or a city? I know people named Regina. I know of a city named Regina. How would you differentiate between the two? I don't think that a regex is the right tool for this. I'm pretty sure both person and city names are far more complex than you've allowed for.

          "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

          1 Reply Last reply
          0
          • K KiranKumar V 2024

            I am working with Data masking in test data management there we are using one tool called javelin workflow to extract data from XML which is inserted into database and To read data we are using regular expression pattern for name and cityname. But our requirement is city name like Birmingham should be masked as fixed value as Norwich and name of person should be masked as random letters, but we are using same regular expression pattern for both and data is not masking as we expected so we want to differentiate them with regular expression

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            If this is coming from an XML file, you SHOULD have fields in the XML specific to each type of name. If not, you have very badly malformed data in the file making it pretty much useless, unless there is another field in the same record telling you what type of name is in the record. Without that discriminator field, the data you're pulling from the XML is useless. You cannot use a RegEx to distinguish between a person name and a city name in the same field. It's just not possible, even for a human to determine by hand.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

            K 1 Reply Last reply
            0
            • D Dave Kreskowiak

              If this is coming from an XML file, you SHOULD have fields in the XML specific to each type of name. If not, you have very badly malformed data in the file making it pretty much useless, unless there is another field in the same record telling you what type of name is in the record. Without that discriminator field, the data you're pulling from the XML is useless. You cannot use a RegEx to distinguish between a person name and a city name in the same field. It's just not possible, even for a human to determine by hand.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

              K Offline
              K Offline
              KiranKumar V 2024
              wrote on last edited by
              #6

              XML element looks like for name of person And in the same XML for cityname And in same XML cityname having all caps letter like So suggest me regular expression for Cityname for both cases Birmingham and BIRMINGHAM because I want to proceed name for different function and cityname for different function in data masking tool. And regular expression for name of person like "Jeff"

              Richard DeemingR D 2 Replies Last reply
              0
              • K KiranKumar V 2024

                XML element looks like for name of person And in the same XML for cityname And in same XML cityname having all caps letter like So suggest me regular expression for Cityname for both cases Birmingham and BIRMINGHAM because I want to proceed name for different function and cityname for different function in data masking tool. And regular expression for name of person like "Jeff"

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                You really are determined to ignore what you're being told, aren't you?! :doh: It is literally impossible to use a regex to determine whether a sequence of characters refers to a person, a city, a talking kangaroo, or a Vulcan mating ritual. Your only hope is to get a massive database containing the name of every single city on Earth, and hope that anything that's not in that list refers to a person. And even that's not foolproof - for example, "Paris" could be a city or a person. Without more details, you have no way of knowing. The data you're trying to process is garbage. If you need to be able to tell whether the data refers to a person or a city, then you need to go back to the people providing the data and get them to add something into the data to distinguish the two. Assuming they know the difference in the first place!


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                D L J 3 Replies Last reply
                0
                • K KiranKumar V 2024

                  XML element looks like for name of person And in the same XML for cityname And in same XML cityname having all caps letter like So suggest me regular expression for Cityname for both cases Birmingham and BIRMINGHAM because I want to proceed name for different function and cityname for different function in data masking tool. And regular expression for name of person like "Jeff"

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  It's simply not possible. There is no expression that will be able to tell you whether the name is a person or a city. NONE AT ALL. If you're trying to extract the names from the XML file, you DO NOT USE A REGEX FOR THIS. You create classes to hold each type of record and deserialize the XML into a data structure using those classes. But, since you're get both city names and person names in the same record type (whatever "ab" means), there is no code you could ever write to tell you whether that is a person or a city.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

                  1 Reply Last reply
                  0
                  • Richard DeemingR Richard Deeming

                    You really are determined to ignore what you're being told, aren't you?! :doh: It is literally impossible to use a regex to determine whether a sequence of characters refers to a person, a city, a talking kangaroo, or a Vulcan mating ritual. Your only hope is to get a massive database containing the name of every single city on Earth, and hope that anything that's not in that list refers to a person. And even that's not foolproof - for example, "Paris" could be a city or a person. Without more details, you have no way of knowing. The data you're trying to process is garbage. If you need to be able to tell whether the data refers to a person or a city, then you need to go back to the people providing the data and get them to add something into the data to distinguish the two. Assuming they know the difference in the first place!


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    Richard Deeming wrote:

                    or a Vulcan mating ritual.

                    :laugh: :laugh: :laugh:

                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

                    1 Reply Last reply
                    0
                    • K KiranKumar V 2024

                      I have two scenarios in table one is name of person and another is cityname but both name of the person and cityname starts with capital letter and followed by small letters I want different regular expression for cityname and name of person but both starts with capital letter and followed by small letters how can I differentiate them with regular expression.

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      It's impossible. Suppose you are just looking at surname and city, then my local city defeats this. Am I looking for the magician with the surname Durham[^], or the city in England[^]?

                      Advanced TypeScript Programming Projects

                      1 Reply Last reply
                      0
                      • Richard DeemingR Richard Deeming

                        You really are determined to ignore what you're being told, aren't you?! :doh: It is literally impossible to use a regex to determine whether a sequence of characters refers to a person, a city, a talking kangaroo, or a Vulcan mating ritual. Your only hope is to get a massive database containing the name of every single city on Earth, and hope that anything that's not in that list refers to a person. And even that's not foolproof - for example, "Paris" could be a city or a person. Without more details, you have no way of knowing. The data you're trying to process is garbage. If you need to be able to tell whether the data refers to a person or a city, then you need to go back to the people providing the data and get them to add something into the data to distinguish the two. Assuming they know the difference in the first place!


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Richard Deeming wrote:

                        "Paris" could be a city or a person.

                        Paris Hilton - Wedding, Photos, Videos, Celebrity, Entrepreneur, Advocate[^]

                        1 Reply Last reply
                        0
                        • Richard DeemingR Richard Deeming

                          You really are determined to ignore what you're being told, aren't you?! :doh: It is literally impossible to use a regex to determine whether a sequence of characters refers to a person, a city, a talking kangaroo, or a Vulcan mating ritual. Your only hope is to get a massive database containing the name of every single city on Earth, and hope that anything that's not in that list refers to a person. And even that's not foolproof - for example, "Paris" could be a city or a person. Without more details, you have no way of knowing. The data you're trying to process is garbage. If you need to be able to tell whether the data refers to a person or a city, then you need to go back to the people providing the data and get them to add something into the data to distinguish the two. Assuming they know the difference in the first place!


                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                          J Offline
                          J Offline
                          jschell
                          wrote on last edited by
                          #12

                          Richard Deeming wrote:

                          or a Vulcan mating ritual.

                          Are you sure? There probably could be more than one but I suspect the names are going to be pretty unique.

                          1 Reply Last reply
                          0
                          • K KiranKumar V 2024

                            I have two scenarios in table one is name of person and another is cityname but both name of the person and cityname starts with capital letter and followed by small letters I want different regular expression for cityname and name of person but both starts with capital letter and followed by small letters how can I differentiate them with regular expression.

                            J Offline
                            J Offline
                            jschell
                            wrote on last edited by
                            #13

                            KiranKumar V 2024 wrote:

                            regular expression for cityname and name of person

                            You stated in the other post

                            Go to ParentXML element looks like for name of person

                            And in the same XML for cityname

                            And in same XML cityname having all caps letter like

                            As suggestion from another response it is NOT possible for you to determine from the above which is a city and which is a persons name. HOWEVER, what you posted is not valid XML. It would seem possible to me that there are other XML elements that you can use. But if not then I would immediately point out to whoever assigned this to you that it is NOT deterministic. A computer can NOT solve the problem correctly. Doesn't matter how you do it. But with you posted the ONLY solution you have right now would be with the following. - You must buy a city database. That is a product/service that one pays money for. - You then use XML to parse the data. You do NOT use regular expressions to parse it. - You look up the each value in the database. If you find it is a city. If you don't it is a name. Following is an actual list of cities named after people. So of course these are the one that a computer cannot tell the difference. Actually human will not be able to tell it either. https://en.wikipedia.org/wiki/List\_of\_places\_in\_the\_United\_States\_named\_after\_people Now in terms of other possibilities. - There is in fact a person name AND city name in each record. So you could use that in combination with the above. - As I said there are other elements/attributes in the XML that define exactly what it is. - You can request that they change the XML to make it clear which is a city and which is a name.

                            Richard DeemingR 1 Reply Last reply
                            0
                            • J jschell

                              KiranKumar V 2024 wrote:

                              regular expression for cityname and name of person

                              You stated in the other post

                              Go to ParentXML element looks like for name of person

                              And in the same XML for cityname

                              And in same XML cityname having all caps letter like

                              As suggestion from another response it is NOT possible for you to determine from the above which is a city and which is a persons name. HOWEVER, what you posted is not valid XML. It would seem possible to me that there are other XML elements that you can use. But if not then I would immediately point out to whoever assigned this to you that it is NOT deterministic. A computer can NOT solve the problem correctly. Doesn't matter how you do it. But with you posted the ONLY solution you have right now would be with the following. - You must buy a city database. That is a product/service that one pays money for. - You then use XML to parse the data. You do NOT use regular expressions to parse it. - You look up the each value in the database. If you find it is a city. If you don't it is a name. Following is an actual list of cities named after people. So of course these are the one that a computer cannot tell the difference. Actually human will not be able to tell it either. https://en.wikipedia.org/wiki/List\_of\_places\_in\_the\_United\_States\_named\_after\_people Now in terms of other possibilities. - There is in fact a person name AND city name in each record. So you could use that in combination with the above. - As I said there are other elements/attributes in the XML that define exactly what it is. - You can request that they change the XML to make it clear which is a city and which is a name.

                              Richard DeemingR Offline
                              Richard DeemingR Offline
                              Richard Deeming
                              wrote on last edited by
                              #14

                              jschell wrote:

                              If you find it is a city. If you don't it is a name.

                              Paris[^]? Durham[^]? London[^]? Adelaide[^]? Etc. There are plenty of examples that could be either a city or a name. Using not in the list of cities === person test might give you a good start, but its never going to be 100% accurate. :)


                              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                              J 1 Reply Last reply
                              0
                              • Richard DeemingR Richard Deeming

                                jschell wrote:

                                If you find it is a city. If you don't it is a name.

                                Paris[^]? Durham[^]? London[^]? Adelaide[^]? Etc. There are plenty of examples that could be either a city or a name. Using not in the list of cities === person test might give you a good start, but its never going to be 100% accurate. :)


                                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                J Offline
                                J Offline
                                jschell
                                wrote on last edited by
                                #15

                                Richard Deeming wrote:

                                but its never going to be 100% accurate.

                                Was the phrasing in my response not clear? I thought I was pointing that out in several places.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups