# Using a RegExp, Help Needed

**URL:** <https://forum.kirupa.com/t/using-a-regexp-help-needed/234241>\
**Category:** Uncategorized\
**Created:** [July 31, 2007, 6:05pm UTC](https://forum.kirupa.com/t/using-a-regexp-help-needed/234241 "2007-07-31T18:05:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gokujou](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gokujou](https://forum.kirupa.com/u/gokujou)\
**Post date:** [July 31, 2007, 6:05pm UTC](https://forum.kirupa.com/t/using-a-regexp-help-needed/234241/1 "2007-07-31T18:05:10Z")

</div>

Hello,  
I am trying to create a weather app in Flex Builder 2 but I have an issue.  
The XML comes in with hyphens in the names and as a string and AS3 didn’t like that.

I went through and converted all the hyphens to underscores, that worked I thought, but then when a negative value for a measurement comes in it is no longer a number. So know I am trying a RegExp to change all the hyphens followed by an alpha character to underscores. I am getting out of my league now being a measly interface designer and I want to see if anyone can help me clean up the code to get it to work. I had it working in Flash CS3 but Flex is a little more strict it seems. Here it is:

```auto

            // resultHandler
            private var wxDataString:String;
            
            private function resultHandler(event:ResultEvent):void {
                wxDataString = event.result as String;
                wxDataString = findSearchReplace(wxDataString);
                var wxData:XML = new XML(wxDataString);
                lat = wxData..@latitude;
                lon = wxData..@longitude;
                trace(wxData..@period_name[0]);                
                //Display New Cords
                myCord = "N" + lat + " W" + lon;
                latInput.text = lat + "";
                lonInput.text = lon + "";
                dayBox1.nameOfDay.text = wxData..@period_name[0];
                dayBox2.nameOfDay.text = wxData..@period_name[1];
                dayBox3.nameOfDay.text = wxData..@period_name[2];
                dayBox4.nameOfDay.text = wxData..@period_name[3];
                dayBox5.nameOfDay.text = wxData..@period_name[4];
            }
            
            private var sNew:String = "";
            private var i:Number = 0;
            private var searchResult:Array = [0];
            
            private function findSearchReplace(wxDataString:String):String {
                for (i=0; searchResult!=null; i++) {
                    // RegExp Info
                    var textSearch:RegExp = new RegExp("-[A-Za-z]", "g");
                    searchResult = textSearch.exec(wxDataString);
                    trace(typeof(searchResult[0]));
                    strReplace(searchResult[0], "-", "_");
                    trace(searchResult);
                    strReplace(wxDataString, searchResult[0], sNew);
                }
                return wxDataString;
            }
            private function strReplace(str:String, search:String, replace:String):String {
                return str.split(search).join(replace);
            }

```

Thanks for any help you can give. Thank you very much.
