# Separate Alphanumeric string from input box into 3 separate strings

**URL:** <https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420>\
**Category:** Ignition\
**Created:** [July 7, 2020, 6:21am UTC](https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420 "2020-07-07T06:21:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![juang](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@juang](https://forum.inductiveautomation.com/u/juang)\
**Post date:** [July 7, 2020, 6:21am UTC](https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420/1 "2020-07-07T06:21:01Z")

</div>

I need to separate the text to pass the information to 3 different tags. string length will be different so i can’t just use a split or substring to separated.  
What i’m trying to achieve with this is to access any in a Siemens PLC, for example a Technician would type in the input boxes “M500.0” then I need to get “M”,“500”,“0”, all three separated, which i could do if the length of the string was always the same, but they can also type “M1000.7” or “MW300” or “PIW346” so here is where i run into my problem. As I can’t use the same code for all this variations. ideally what i would be looking for, would be something that would get the index of the last letter or the first number and do the first split there , then use the “.” for the other split, if there is a “.” , in the case of MW and PIW I don’t even need to split a second time because there is not bit value.

This is my ignition Screen.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/316e777764427ce53a7cd0c0efae8c3c5a930161.png)

Originally I had design this in a Weintek Hmi using a Dropdown to select the Data type (M, MW, I, Q,PIW and so on) then use two different input box to type the rest. i pass this to a S7 STL code and from there i read the status of the selected address and give the Status back. this way Maintenance tech can troubleshoot without the need of going into the PLC. With Ignition I thought it would be better to do Multiple status check as the same time for different addresses. that way they can probably check the status of a full network by just typing the address that they have on the printed program, this is a much needed solution for our company.

Using the dropdown and two different input boxes does not make much sense as i can have them just type the address in an input and i separate into 3. well at least that is what I wanted to do. but so far no luck.

so if anyone can help it would be really appreciated. and i would gladly provide the STL code if someone wants it for them. this a anypointer STL code to get any address in the PLC without the need of opening a DB or anything. and it would work on any program as long as the FC is called.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [July 7, 2020, 6:55am UTC](https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420/2 "2020-07-07T06:55:26Z")

</div>

Hi,

My idea is to check every characters of the whole string and divide them into letters and numbers  
Here it is the script:

You can do it with strings directly:

```auto
a = 'PIW346'

numbers = ''
letters = ''

for x in range(len(a)):
	if a[x].isnumeric():
		numbers += a[x]
	elif a[x].isalpha():
		letters += a[x]
	elif a[x] == '.':
		bit_value = a[x+1]
		break

print numbers
print letters
print bit_value

```

or you can do it with lists:

```auto
a = 'M300.0'

numbers = []
letters = []

for x in range(len(a)):
	if a[x].isnumeric():
		numbers.append(a[x])
	elif a[x].isalpha():
		letters.append(a[x])
	elif a[x] == '.':
		bit_value = a[x+1]
		break

print numbers
print letters
print bit_value

```

I tested it with all the “possibilities” you gave us in the post and it worked all the time.

Hope this will help you

Cheers,

---

<div class="post-metadata">

**Author:** ![juang](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@juang](https://forum.inductiveautomation.com/u/juang)\
**Post date:** [July 7, 2020, 7:12am UTC](https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420/3 "2020-07-07T07:12:30Z")

</div>

I will test tomorrow morning but yes it make sense and it should work . Thanks so much .

---

<div class="post-metadata">

**Author:** ![lewis.storey](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lewis.storey/32/15026_2.png) [@lewis.storey](https://forum.inductiveautomation.com/u/lewis.storey)\
**Post date:** [July 7, 2020, 8:44am UTC](https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420/4 "2020-07-07T08:44:17Z")

</div>

Another option is to use regex and split. This is a bit more verbose than it can be but much more readable for it.

```auto
import re

testS = 'M1000.7'

letterMatch = r'(\D*\B)'
numberMatch = r'((?:(?!.).)*\d+)'

# Find all letters from start of string until the first digit. Returns an array of one in this case
letters = re.findall(letterMatch,testS)[0]
# First group captured is all numbers after the letters but before the dot
numbers = re.findall(numberMatch,testS)[0]
# If there is a dot, grabs everything after it
bit = ''
if '.' in testS:
    bit = testS.split('.')[1]

print letters # prints M
print numbers # prints 1000
# bit evaluates to false if it is empty
if bit: print bit # prints 7

```

All three variables will be strings just in case that matters but they will be easily castable

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 7, 2020, 4:10pm UTC](https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420/5 "2020-07-07T16:10:40Z")

</div>

Different regex approach (I would also recommend regex for this):  
`^([A-Z]+)(\d+)((?:\.)\d+)?`  
Group 1 is the data type, group 2 is the address, group 3 (if present) is the bit address.

> **[regex101: build, test, and debug regex](https://regex101.com/r/NzFU8C/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java. Features a regex quiz & library.

---

<div class="post-metadata">

**Author:** ![juang](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@juang](https://forum.inductiveautomation.com/u/juang)\
**Post date:** [July 17, 2020, 4:30am UTC](https://forum.inductiveautomation.com/t/separate-alphanumeric-string-from-input-box-into-3-separate-strings/36420/6 "2020-07-17T04:30:48Z")

</div>

thanks everyone. it works with any of those options.
