Problem with the String Variable

Hi Team,

While I am Storing data in a string variable by using read word activity and extract a string using a Regex. it’s not working.

if the take the same string in a assign activity and pass the hardcoded value apply regex it’s working fine.

can some one help me in resolving the issue

@Venkatesh_Velamuri1

Welcome to the community

may be there are some special characters in the string when you extract or it is little different…try finding the difference between the string when hardcoded and when reading

You can use locals panel to check

cheers

Hi @Venkatesh_Velamuri1

  1. Check the output of the Read Word activity: Ensure that the Read Word activity is successfully retrieving the desired content from the Word document. You can use a Write Line activity to output the value of the string variable after the Read Word activity. Verify that the extracted text appears as expected.
  2. Verify the regex pattern: Double-check the regex pattern you are using to extract the desired string. Make sure the pattern is correctly defined and matches the expected format of the text you are trying to extract. You can test your regex pattern using online regex testers (such as regex101.com) to verify its correctness.
  3. Use the appropriate regex activity: UiPath provides dedicated activities for working with regex patterns. Instead of using the Assign activity with a hardcoded value, try using the Matches or IsMatch activity from the UiPath.Core.Activities package. These activities are specifically designed to work with regular expressions and provide more control over pattern matching and extraction.
  4. Ensure that the input string is not null or empty: Verify that the string variable obtained from the Read Word activity is not null or empty before applying the regex pattern. You can use an If activity with a condition like String.IsNullOrEmpty(yourStringVariable) to handle such cases gracefully.
  5. Check for leading/trailing whitespaces or line breaks: Sometimes, the extracted text may have leading or trailing whitespaces or line breaks that affect the regex pattern matching. You can use the Trim method (e.g., yourStringVariable.Trim()) to remove any unwanted whitespaces or line breaks before applying the regex pattern

Hope it helps!!