You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dynatrace用户会话标签清理:提取SharePoint用户名正则需求

Extracting First-Last Name from SharePoint Header Text (Dynatrace Tagging)

Got it, let's build a regex that handles both your SharePoint header formats and outputs the name in "First Name Last Name" order for your Dynatrace user session tags.

The Regex & Replacement Logic

Use this regular expression to match the username segment, then swap the captured groups to reorder the name:

Match Pattern:

^([^,]+),\s*([^\s\n]+)(?:\s|\n)

Replacement String:

$2 $1

How It Works

Let's break down each part of the match pattern to make sure it fits your use case:

  • ^: Anchors the match to the start of the text (ensures we're grabbing the very first username segment)
  • ([^,]+): Captures the last name (everything up to the comma) into Group 1
  • ,\s*: Matches the comma followed by any number of whitespace characters (handles cases where there's a space after the comma, or none)
  • ([^\s\n]+): Captures the first name (everything up to the first space or newline) into Group 2
  • (?:\s|\n): Matches either a space or a newline (the separator between the username and the prompt text) — the (?:...) makes this a non-capturing group so it doesn't interfere with our name groups

Testing with Your Examples

Let's verify it works for both your input formats:

Example 1: Space Separator

Input:

Smith, John Use SHIFT+ENTER to open the menu (new window).
  • Group 1 captures Smith, Group 2 captures John
  • Replacement gives: John Smith

Example 2: Newline Separator

Input:

Smith, John
Use SHIFT+ENTER to open the menu (new window).
  • Group 1 captures Smith, Group 2 captures John
  • Replacement gives: John Smith

Bonus: Making It Even More Flexible

If you want to ignore any trailing prompt text entirely (not just match up to the space/newline), you can adjust the pattern to:

^([^,]+),\s*([^\s\n]+)

This will just grab the last-name-first segment regardless of what comes after, which might be useful if the prompt text ever changes slightly.

内容的提问来源于stack exchange,提问作者Davide Piras

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:46:10